Opening a Subform Record based on field on Main Form

G

Guest

I know I have to use the OpenForm method, as is used on Orders subform on the
template database on the Orders by Customer form, but I've tried this with
combining the Access template databases - Order Entry and Customers...I want
to have a button to open the Calls subform (from Customers form on Customers
database) from the Orders by Customer form based on the id of the customer.
Any suggestions? Right now, all I can get it to do is open the entire
recordset of calls when I click the Calls button I added to the form. Am I
making sense?
 
G

Guest

To open another form based on the current record, use the linking key field
as the criteria parameter of the OpenForm method (see VBA Help for a
description of all parameters). Something like the following, which opens a
form for the local distributor of the currently displayed manufacturer:

Private Sub cmdOpenDistributorForm_Click()
On Error GoTo Err_cmdOpenDistributorForm_Click

Dim stDocName As String
Dim stLinkCriteria As String

' Put the formname you'd like to open here
stDocName = "frmDistributors_Reps"

' stLinkCriteria is a String variable. That's why the key field, in
this case,
' [DistID], is enclosed in quotes

' Also, in this case, cboDistName is a control on the same form as the
button
' that was pressed. If your subform does not have the linking field,
you can either
' add it as a non-visible control, or, assuming it is on the main form,
refer to it
' explicitly, rather than using the Me! shortcut:
'
' Forms!YourMainFormName!YourControl
'
stLinkCriteria = "[DistID]=" & Me![cboDistName]
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_cmdOpenDistributorForm_Click:
Exit Sub

Err_cmdOpenDistributorForm_Click:
MsgBox Err.Description
Resume Exit_cmdOpenDistributorForm_Click

End Sub

HTH
Sprinks
 

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