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

How to set record source for dynamic form 1

Status
Not open for further replies.

Form1

Programmer
Apr 27, 2005
12
How to set the record source for a form where form name
varies depending on where it is called?
My form name is stored in stFormName
I have to set this property in different form.

I tried following but doesn't work
Forms(stFormName).RecordSource = mstrSQL
Forms!stFormName.RecordSource = mstrSQL



Any suggestion is appreciated.
Thanks

 
Provided that stFormName is a loaded main form, the following should work:
Forms(stFormName).RecordSource = mstrSQL
If stFormName is a subform in the current form, then try this:
Me(stFormName).Form.RecordSource = mstrSQL

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Thanks for your response but this doesnot work
Forms(stFormName).RecordSource = mstrSQL
My form is not a subform.

Here is the scenario, my form name is stored in a variable stFormName it's not a form. So when I try
Forms(stFormName).RecordSource = mstrSQL
the message I get is stFormName form not found.
I checked it in Debugger mode when stFormName has my form name but still the above statement doesn't work.
Any idea why and how to do it?

Thanks
 
Forms.Item(stFormName).RecordSource = mstrSQL worked.

dim stablename as string
stablename = Me.OpenArgs

I have one more problem. My table name is a variable which is stored in stablename

dim stablename as string
stablename = Me.OpenArgs
mstrSQL = Select * from stablename;

when I use stablename in SQL statement
it says stablename is not table/query.
If I hardcode the tablename it works.
How to solve this?
 
Try this:

Code:
mstrSQL = "SELECT * FROM " & stablename & ";"

HTH

Ken S.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top