Need to Filter Query with textbox

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jmshipe
    New Member
    • Aug 2012
    • 9

    Need to Filter Query with textbox

    Okay, so I know this sounds easy, but for some reason I'm having alot of trouble working this out. I've looked for the answer on other posts, but nothing has worked.

    I have a form with a text box ("txtbox1"). When this number is updated with the update function I want it to filter a query WHERE [Field] = "txtbox1" value.

    The query is displayed in a subform. It draws its information from one table.

    My code is a mess right now so I won't post it. I can answer any questions though.

    Thank You
  • twinnyfo
    Recognized Expert Moderator Specialist
    • Nov 2011
    • 3653

    #2
    Proper syntax should be:

    Code:
    "SELECT * FROM tblTableName WHERE [Field] = '" & Me.txtbox1 & "';"
    If you are just filtering the subform, you can filter the subform directly fromthe main form:

    Code:
    Me.fsubFormName.Form.Filter = "[Field] = '" & Me.txtbox1 & "'"
    Me.fsubFormName.Form.FilterOn = True
    I think this is the direction you want to go?

    Comment

    • jmshipe
      New Member
      • Aug 2012
      • 9

      #3
      Okay well I'm getting a "Data type mismatch in criteria expression"

      I tried putting the textbox name and value variable name.

      'Variable for aRxNumber textbox
      Dim rxNum As Long
      rxNum = Val(Nz([Form_Log Form].aRxNumber.Valu e, 0))

      Me.rxQuery.Form .Filter = "[Rx Number] = '" & rxNum & "'"
      Me.rxQuery.Form .FilterOn = True

      Comment

      • twinnyfo
        Recognized Expert Moderator Specialist
        • Nov 2011
        • 3653

        #4
        It was unclear as to whether this field was a text or a number. It appears to be a number. Try removing the single quote in the expression, like so:

        Code:
        Me.rxQuery.Form.Filter = "[Rx Number] = " & rxNum
        Also, as a gentle reminder, please use the code tags when posting your code.

        Hope this helps, my friend.....

        Comment

        • jmshipe
          New Member
          • Aug 2012
          • 9

          #5
          It worked! Thank you again for the help and guidance.

          Comment

          Working...