command button

K

keith

Using the wizard, I have created a command button that
pulls up a subform based upon query. However, I want to
use the same subform for other popups - all referencing a
different query. I don't want to create multiple
subforms but would rather use only one. How can I do
this?
 
K

Karen

Keith,

I'm still a newbie but I would use the 'where' and the 'openargs' of the
DoCmd.Open.

DoCmd.OpenForm stDocName, , , stLinkCriteria, , ,"MainFormCallingSubForm"

Then I would put VBA in the OnOpen property of the subform to check the
'OpenArgs' and use that to determine which query was supposed to be the
recordsource for that form.

If Me.openargs = "FirstMainForm" then
Me.recordsource = SQL1 (or query1)
ElseIf me.openargs = "SecondMainForm" then
Me.recordsource = SQL2 (or query 2)
..
..
..
End If

A case statement would also work out well.

Karen
 
K

keith

Yes I believe this is the way to go, however I am not
sure how to do this. Can you elaborate on the code?
-----Original Message-----
You will need to "dynamically" set the Record Source of the subform.

RDH



------------------------------------------------
 
G

Guest

I would suggest the following:
The event procedure code that occurs with the click event
would read:

Me.SubFormName.RecordSource= "put a SELECT statement or
query name here"

RS
 
K

Kelvin

In the code of the command button add:

Forms!frmNameOfForm.RecordSource = "nameOfQuery"
Forms!frmNameOfForm.Requery

Add similar code to other buttons. If the query to choose is based on a
value on the current form, just put the code in an IF then statement.

If Me.txtNameOfTextBox = "Annual" then
Forms!frmNameOfForm.RecordSource = "nameOfAnnualQuery"
Else if Me.txtNameOfTextBox = "Quarterly" then
Forms!frmNameOfForm.RecordSource = "nameOfQuarterlyQuery"
End if
Forms!frmNameOfForm.Requery

Kelvin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top