Changing a Form's Record Source..

Sean25

Registered User.
Local time
Yesterday, 21:15
Joined
Feb 16, 2004
Messages
25
Is it possible through code to change a form's record source PRIOR to the form being opened on the screen?

Example:

Form 'A' is set so that Record Source is a Table.

Primary Form has two buttons, both which open Form 'A'.

I want the one button to open Form 'A' as is, but I would like the other button to open Form 'A' with the Record Source being a Query, as opposed to the table.

I can change the Record Source after opening the Form 'A' with DoCmd.Open, but this looks messy, as the query box opens on top of the Newly opened form, as opposed to popping up prior to the form appearing, as it would if the form's record source was by default set to the Query.

I hope this isn't too muddled a question. I thank all in advance for any advice or assistance that can be lent.

S.
 
Yes, this is possible. You can pass along some information to a form when you open it, either using the form's OpenArgs property, or the form's Tag property. OpenArgs is better in this case.

Use code like this behind your first button:
DoCmd.OpenForm "formName",,,,,,"normal"
and code like this behind the second:
DoCmd.OpenForm "formName",,,,,,"query"

Then in the form you are opening, have code in it's Open event that checks the OpenArgs value and takes the appropriate action. Something like this:
Code:
If Me.OpenArgs="query" Then
    Me.RecordSource=[i]query name[/i]
End If
 
thanks...

Thanks, again. That worked great.

Hopefully I don't post too many more "stupid" questions, (and or just miss the obvious in the replies as before) although I am working through a few issues right now that I may need to pick some more brains about.


S.
 
It's no problem. Good luck.
 

Users who are viewing this thread

Back
Top Bottom