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

Set recordsource of another form before opening it

Status
Not open for further replies.

jmstarbuck

Programmer
Aug 11, 2003
90
US
I have two forms. Form1 is using a DOCmd.OpenForm to open Form2.

Is there a way to set the recordsouce for Form2 while still in Form1?

Thanks.
 
Forms!Form2.RecordSource = "what ever you want"

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks for your reply.

That's what I thought. However, I get runtime error '2450'

Can't find the form 'DetachFile_Form' referred to in the macro or Visual Basic code.

Any thoughts?
 
Can you post your code? Likely your form "DetachFile_Form" is not open or its name is something different than "DetachFile_Form". By chance is it actually called "DetachFile"?
 
Please, post the code opening the form and assigning the RecordSource.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Well, I just noticed the thread's subject:
Set recordsource of another form before opening it|/i]
Set the RecordSource AFTER opening it !

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
You can also use a saved query as the record source and set the SQL property of the saved query prior to opening the form. Make sure you have a split application if this is shared.

You can also set a WHERE CONDITION in the DoCmd.OpenForm method that allows you to filter the records returned in a form.

Duane
Hook'D on Access
MS Access MVP
 
This is the way I normally change record sources:
Code:
DoCmd.OpenForm "Form2", acNormal
Forms!Form2.RecordSource = "(New SQL Statement, table name or query name)"
Forms!Form2.Requery
If you want to close Form1 add: DoCmd.Close acForm, "Form1", acSaveNo


AtlasAF
 
Thanks for all the suggestions. I have discovered that my problem was that I was opening the form with WindowMode = ACdialog.

Consequently, once I opened the form I no longer had control from the form that called it. I got control back only when Form2 was closed. Then it tried to set the recordsource...yada, yada, yada.

After further reflection I think I will just go with the where parameter.

I'm truly grateful to those who replied.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top