Open a subform by ID

  • Thread starter John Harrington
  • Start date
J

John Harrington

If I want to make a button on MyOpenForm that opens a form with a
table record source to a specific ID (e.g., 2) in the table, I write
the following in the buttons click event:

DoCmd.OpenForm "MyForm", , , "ID = 2"

Suppose I have MyForm embedded in MyOtherForm as a subform. How would
I rewrite the above line so that the subform opens to record ID 2?

Thanks,
John
 
K

Klatuu

You don't open subforms. Subforms are a bit different. What you have is a
form being used as a subform. It is contained in a subform control on the
main form. One of the properties of a subform control is the SourceObject
property. It identifies which form will be presented in the subform control.

So, the answer is you just set the value of the SourceObject property of the
subform control to the name of the subform you want to present. Because of
this, you don't have the Where argument to use to identify the record. That
can be accomplished by navigating the subform's recordset to the desired
record.

It would be something like this untested "air code":

With Me.MySubFormControl
.SourceObject = "MySubFormName"
With .Form.Recordset
.FindFirst "ID = 2"
If Not .NoMatch Then
Me.MySubFormControl.Form.Bookmark = .Bookmark
End If
End With
End With
 

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