Referring to a object in a subform?

  • Thread starter Thread starter Steve
  • Start date Start date
S

Steve

The following code is being used to open a specific form
depending on the value of an Textbox object
(EquipmentType) in a subform (fsubDeviceCheck) which is a
subform of form (frmDeviceCheck). The (NewCheck) button
is on the master form (frmDeviceCheck). When I click on
this button I get the following error: "Microsoft Access
can't find the field 'fsubDeviceCheck' referred to in
your expression". Why does it think 'fsubDeviceCheck' is
a field instead of recognizing that it is a subform?
Thank-you for your help.

Private Sub NewCheck_Click()
On Error GoTo Err_NewCheck_Click

Dim stDocName As String
Dim stLinkCriteria As String


If Forms![frmDeviceCheck]![fsubDeviceCheck]!_
EquipmentType = "Pulse Generator" Then

stDocName = "frmDeviceCheckDataEntry"
DoCmd.OpenForm stDocName, , , stLinkCriteria

End If

Exit_NewCheck_Click:
Exit Sub

Err_NewCheck_Click:
MsgBox Err.Description
Resume Exit_NewCheck_Click

End Sub
 
If Forms![frmDeviceCheck]![fsubDeviceCheck]!_
EquipmentType = "Pulse Generator" Then

Is fsubDeviceCheck the name of the *form object* inside the subform
control, or the name *of the control itself*, the box on the mainform?
It's the latter that is required.

I'd suggest being explicit and using

Forms![frmDeviceCheck]![fsubDeviceCheck],Form!EquipmentType
 
Back
Top