Opening a form from within a subform using a macro

G

Guest

I wish to open a form from within a sub form.
Main form - Contact details - ContactID
Subform - property details - Property ID
Advertising Form to Open contains PropertyID
If the Property form is stand alone, I can create a macro that uses IsLoaded
and Open the Advertising form to the correct Property ID using Where
PropertyID=PropertyID (I have left actual detail out)
This doesn't work at all when the property form is a SubForm.
Is there a way I can get this to work?
 
L

Larry Linson

john@leeburn said:
I wish to open a form from within a sub form.
Main form - Contact details - ContactID
Subform - property details - Property ID
Advertising Form to Open contains PropertyID
If the Property form is stand alone, I can create a macro that uses
IsLoaded
and Open the Advertising form to the correct Property ID using Where
PropertyID=PropertyID (I have left actual detail out)
This doesn't work at all when the property form is a SubForm.
Is there a way I can get this to work?

There's nothing to keep you from executing a DoCmd.OpenForm from within the
VBA code of a Form embedded in a Subform Control. "Doesn't work" also
doesn't give us much to go on. Neither does "leaving out the actual detail"
because, almost certainly, "the Devil's in the details."

If you really mean "Access macro" instead of VBA code, then someone else is
going to have to pick up once you give us the details. The only macros I
have used in recent years are AutoExec and AutoKeys.

Larry Linson
Microsoft Access MVP
 
G

Guest

Larry Linson said:
There's nothing to keep you from executing a DoCmd.OpenForm from within the
VBA code of a Form embedded in a Subform Control. "Doesn't work" also
doesn't give us much to go on. Neither does "leaving out the actual detail"
because, almost certainly, "the Devil's in the details."

If you really mean "Access macro" instead of VBA code, then someone else is
going to have to pick up once you give us the details. The only macros I
have used in recent years are AutoExec and AutoKeys.

Larry Linson
Microsoft Access MVP
OK thanks for replying. Here's some more detail:
I have a contacts form with a subform.
From the Marketing Options subform, I wish to open a report, but only one
record based on the OptionID within the subform. I have a control button that
runs the code below. It works when the form is open on it's own and not
imbheedded in the Contacts Form as a subform. When I use the control button
in the subform, it calls for me to enter the OptionID .. it then opens the
report with the correct data. I would prefer not to have to enter the
OptionID. So hope this is clearer ... it works just fine on its own but not
when it in the subform.
Cheers and thanks,
John

Private Sub Marketing_Click()
On Error GoTo Err_Marketing_Click

Dim stDocName As String

stDocName = "MarketingOption"
DoCmd.OpenReport stDocName, acPreview, ApplyFilter, "OptionID =
Forms![MarketingOptions]![OptionID]"

Exit_Marketing_Click:
Exit Sub

Err_Marketing_Click:
MsgBox Err.Description
Resume Exit_Marketing_Click

End Sub
 

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