Sending data from a Subform to a form

K

Kevin Sprinkel

Hi, Odessit.

Since your command button is on the main form, you must
use the correct syntax to refer to a control on the
currently selected record of the subform.

Private Sub YourCommandButton_Click()
On Error GoTo Err_YourCommandButton_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "YOURFORMNAMEHERE"

stLinkCriteria = "[YourKeyField]=" & _
Me!YourSubformName.Form!YourSubformControl
' For example, Me!sbfOrders.Form!OrderID

DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_YourCommandButton_Click:
Exit Sub

Err_YourCommandButton_Click:
MsgBox Err.Description
Resume Exit_YourCommandButton_Click

Another option would be to put the command button as a
column in the subform, allowing the user to click on it
directly rather than selecting the record and clicking on
the main form record.

HTH
Kevin Sprinkel
 
Top