Results 1 to 10 of 10
  1. #1
    Join Date
    Nov 2004
    Location
    Crick, just outside Rugby
    Posts
    42

    Red face Unanswered: How do I apply filter query to form

    Good morning,

    I hope someone can help me out again.

    I have a form called 'ShaftData3' to display product characteristics. I am trying to, in effect, filter the information for a chosen shaft number.

    I have already got the command button to run the query (ShaftData Query) which works fine, but it opens a table in datasheet view to display the results rather than updating the current form.

    Can someone tell what I have missed?

    Thank you

    Sherri

  2. #2
    Join Date
    Jan 2004
    Location
    Aberdeen, Scotland
    Posts
    1,067
    Morning Sherri

    Do you not just want to base the form on your query rather than running a seperate command?

    i.e. set the control source to your query

    Dave

  3. #3
    Join Date
    Nov 2004
    Location
    Crick, just outside Rugby
    Posts
    42
    Hi Dave,

    I promise this one isn't as bad as the last.

    The form opens to show a list of all the shaft types which is fine for most things, but sometimes you want to look at just the one. So I thought that the simplest way would be to have a control button on the form to find a specific shaft if you needed to.

    So really I just want it to refresh the current form with the query result.

    Does that make sense?

    This is what I have so far:

    For the 'Find Shaft' button

    Private Sub find_shaft_button_Click()
    On Error GoTo Err_find_shaft_button_Click

    Dim stDocName As String

    stDocName = "ShaftData Query"
    DoCmd.OpenQuery stDocName, acNormal, acEdit

    Exit_find_shaft_button_Click:
    Exit Sub

    Err_find_shaft_button_Click:
    MsgBox Err.Description
    Resume Exit_find_shaft_button_Click

    End Sub

    The query gives me the information I require but just not where I want it.

    Thanks Dave

    Sherri

  4. #4
    Join Date
    Jan 2004
    Location
    Aberdeen, Scotland
    Posts
    1,067
    Hi Sherri

    What i would do is add a combobox to your form woth the row source being your shaft names
    Change the Control source to be a query like

    SELECT yourTable.*
    FROM yourTable
    WHERE ((([yourTable].[ShaftName]) Like IIf([Forms]![yourForm]![yourCombo] Is Null,"*",[Forms]![yourForm]![yourCombo])));

    now either after you change the combo or click a button we can run the query again
    by
    combo changes form
    on the combo choose properties and Events and the AfterUpdate Event
    put in the code Form.Requery

    or after a button is pressed on the button choose properties Events On Click
    and in the code put Form.Requery

    Hope this makes sense

    Dave

  5. #5
    Join Date
    Nov 2004
    Location
    Crick, just outside Rugby
    Posts
    42
    Hi Dave,

    You will be plase dto know that I have successfully added the combo box and it updates the form beautifully when I flick between design view and testing it out.

    But, I don't want other users to change any of the displayed information so I have the form opening in view only mode via a button on my main menu. This is OK but it prevents me from choosing anything from the combo box.
    Is there a way of protecting the displayed information, but also being able to choose other records from the combo box.

    I hope I haven't confused you.

    Sherri

  6. #6
    Join Date
    Jan 2004
    Location
    Aberdeen, Scotland
    Posts
    1,067
    Go to all your textboxes etc. and in the properties window choose enabled = false
    this will stop your users accessing the fields but will display the information for you
    but keep the Combobox on true
    Give it a try and see if this is what you are after

  7. #7
    Join Date
    Jun 2004
    Posts
    40
    hello, Can i have a sample of this how it works.
    i am well interested how u apply query to the form, so that i can understand the basically.
    thanks

  8. #8
    Join Date
    Nov 2004
    Location
    Crick, just outside Rugby
    Posts
    42
    Hi Dave,

    It works but all the boxes are now a horrible grey and you can't make them white again.
    Can I perhaps lock the table rather than the form? Would that work in displaying the information but not being able to change it?

    Thanks

    Sherri

  9. #9
    Join Date
    Nov 2004
    Location
    Crick, just outside Rugby
    Posts
    42
    It's OK - I've done it!

    Rather than setting enabled to no, I set locked to yes and it works - smashing!

  10. #10
    Join Date
    Nov 2004
    Location
    Crick, just outside Rugby
    Posts
    42
    It's OK - I've done it!

    Rather than setting enabled to no, I set locked to yes and it works - smashing!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •