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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help needed assigning a name to a QueryDef 1

Status
Not open for further replies.

teach314

Technical User
Jul 29, 2011
183
CA
hello

I think I'm missing something really obvious.

As shown below, I generate the NAMES of 48 queries that I am about to create and save in a loop. This works fine.

In the For-Next loop, I generate the SQL code for each QueryDef, but I'm having trouble with the NAMEs of the QueryDefs.

For example, when n = 48, I want ...
strQryOutput = "q91c__D2E2_...etc...", NOT strQryOutput = strSQL_n48

Code:
       ...  CODE HERE...

strSQL_n01 = "q91a__A1B1_" & rl_AB & "_tt_DE_" & rl_DE & "___and___D1E1_" & rl_DE & "_tt_AB_" & rl_AB
strSQL_n02 = "q91a__A1B1_" & rl_AB & "_tt_DE_" & rl_DE & "___and___D1E2_" & rl_DE & "_tt_AB_" & rl_AB
... etc ...
strSQL_n48 = "q91c__D2E2_" & rl_DE & "_tt_GH_" & rl_GH & "___and___G2H2_" & rl_GH & "_tt_DE_" & rl_DE


  For n = 1 To 48

        ....   CODE  HERE to build strSQL...

 
[b]        [COLOR=#CC0000]strQryOutput[/color] = "strSQL_n" & Right(CStr(0) & CStr(n), 2)     <------   INCORRECT[b][/b][/b]    
   
        Set db = CurrentDb

        'create saved qry



[b]        Set MyQueryDef = db.CreateQueryDef([COLOR=#CC0000]strQryOutput[/color], strSQL)[/b] 


        Set MyQueryDef = Nothing
        db.Close: Set db = Nothing
        
  Next n



Is there an easy fix?

Thanks in advance

 
I'd use an array instead of 48 variables.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
thanks! That's much better. Works great.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top