viewing query subform based on text box value

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dbdb
    New Member
    • Feb 2009
    • 25

    viewing query subform based on text box value

    Hai, need a help please.

    i have a form to view the query subform
    1. form name : form1
    2. query subform name : subform1
    3. textbox name : txtclass1
    4. command button name : cmd1

    i want to view my query based on the value in the textbox.
    the field in my query are : noreg, class, M2A, M2E, M2M

    if user insert the value "M2A0901" in the textbox then
    Code:
    "Select * from Query where M2A like 'M2A0901' "
    if user insert the value "M2E0901" in the textbox then
    Code:
    "Select * from Query where M2E like 'M2E0901' "
    and so on.

    how do i have to use the runSQL statement. or maybe there is another way to view my data in the subform.

    beside i already try this way for the M2A class
    Code:
    SQL1 = "Select * from query where M2A like ' "& txtclass1 &" ' "
    
    DoCmd.RunSql SQL1
    but when i running this statement there is still error said "syntax error in query, incomplete query caluse"

    can anybody help me please.
    thanks anyway
    Last edited by NeoPa; Apr 4 '09, 12:32 PM. Reason: Please use the [CODE] tags provided
  • Delerna
    Recognized Expert Top Contributor
    • Jan 2008
    • 1134

    #2
    Is the data in the subform based off a query in the queries tab? (in relation to the table tab and the forms tab and the reports tab etc, that is)

    If so you can put a reference to the textbox into the criteria for that field in the subforms query.

    Then you can use the afterupdate or similar event of the textbox to execute the
    Code:
    Me.Requery
    Me.Refresh
    statements in the main form.
    Last edited by NeoPa; Apr 2 '09, 01:28 PM. Reason: Please use the [CODE] tags provided

    Comment

    • dbdb
      New Member
      • Feb 2009
      • 25

      #3
      ok thank you.
      it works

      Comment

      Working...