View Full Version : setting form recordsource using a macro


paulmcdonnell
09-22-2001, 03:21 AM
Hi guys,

I'm using a macro to open a form from the tool bar, but I want to set the form recordsource in the macro. I can't quite seem to find where to put this to get it to work... Any ideas


Thanks in advance

paul

jwindon
09-22-2001, 05:09 AM
You can set the WHERE part of the arguments for the form in the macro. If you set the action OpenForm, the arguments appear on the bottom. FormName:, View:, WHERE:,etc.

You can use the build button next to WHERE to help build your criteria.

Is that what you were wanting?

paulmcdonnell
09-22-2001, 05:49 AM
Close.

I have a variable called strsource which changes the record source depending on where the user opens the form from.

I need somehow to set this strsource to the required query name or set the Recordsource property to this

I tried me.recordsource = "query1" and strsource = "query1" in the where condition but neither seem to work... any further ideas..

Thanks so far

paul

jwindon
09-22-2001, 06:04 AM
I was hoping you were NOT trying to alter the record source from your macro, but only looking for filtering.

As is that is NOT the case, I am at a loss to help you. I can suggest at this point only this:

If you are executing the macro from a form, you have set your variable with the code somewhere in there upon a user action/input. That variable (I'm guessing here) is only a temporary house and you need something solid to base your conditions on. Say, an unbound control, set to strsource. Your conditional macro statement would be =Forms!FormYouWereOn![UnboundControlName], the action would be to open Query1 for that line. Subsequent lines would open the other queries or whatever else you wanted to have as options.

Also, although I cannot help with this...You mightlook into the Select Case coding.

paulmcdonnell
09-22-2001, 06:26 AM
Thanks for the effort j

Gonna have another bash in a bit

Cheers
Paul

Pat Hartman
09-22-2001, 06:10 PM
You can't change the recordsource in the macro. However, you can add code to the form's Open event that changes the recordsource based on some conditional logic that you write.

paulmcdonnell
09-24-2001, 01:19 AM
Cheers Pat...

The only thing is if I open the form from the Menubar how does the form know that it is being opened from here. I.e. opening from other forms I set a condition on the click event of the control, but setting the event from the Menu bar is slightly different isn't it...

Cheers
Paul