Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to use variable in a SQL query to substitute form name 1

Status
Not open for further replies.

mini1969

Programmer
Feb 26, 2005
13
BA
The code below shows a query which will get me the row souce data for a combo box(level2) depending on the first combo box selection (level1). The code is simple if it to be used for one form. But I need to use it for so many forms, hence I would like to make function which can dynamically change the formname. When i substitute the "myform" with variable name the code always showing error

SELECT [Level2 data].L2_Name FROM [Level2 data] WHERE ((([Level2 data].L1_Name)=[Forms]![myform]![Level1]))
ORDER BY [Level2 data].L2_Name;

The question is direct, how to make the above code replacing myform with a variable. i use teh variabel like in other SQL code, but it don't work here.
 
strSQL = "SELECT L2_Name FROM [Level2 data] WHERE L1_Name='" & Forms(myform)!Level1 & "' ORDER BY L2_Name"

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Dear PHV,

Thank you verymuch! It worked.

Mini
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top