Connecting Tech Pros Worldwide Help | Site Map

viewing query subform based on text box value

Newbie
 
Join Date: Feb 2009
Location: Jakarta - Indonesia
Posts: 24
#1: Apr 2 '09
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
Expand|Select|Wrap|Line Numbers
  1. "Select * from Query where M2A like 'M2A0901' "
if user insert the value "M2E0901" in the textbox then
Expand|Select|Wrap|Line Numbers
  1. "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
Expand|Select|Wrap|Line Numbers
  1. SQL1 = "Select * from query where M2A like ' "& txtclass1 &" ' "
  2.  
  3. 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
Delerna's Avatar
Expert
 
Join Date: Jan 2008
Location: Sydney
Posts: 783
#2: Apr 2 '09

re: viewing query subform based on text box value


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
Expand|Select|Wrap|Line Numbers
  1. Me.Requery
  2. Me.Refresh
statements in the main form.
Newbie
 
Join Date: Feb 2009
Location: Jakarta - Indonesia
Posts: 24
#3: Apr 2 '09

re: viewing query subform based on text box value


ok thank you.
it works
Reply


Similar Microsoft Access / VBA bytes