So I have a main form, and in the header I have a combo box where a user can search for contacts, but I want the box to search for records in a subform, not on the main form. On the combo box's After Update property I have this code:
In the body of the form I have a subform with the control name "MarketingTargetsSubform", and the main form's name is "Marketing Targets". I'm trying to use a simple doCmd.GoToRecord, but I keep getting the error "An expression you entered is the wrong data type for one of the arguments", and then in the debugger it jumps to the key line:
The subform is not linked to the main form in any way (no child or master fields)
I've checked syntax and googled as much as I can on the topic. Any suggestions?
Code:
Private Sub cboNameSearch_AfterUpdate()
On Error GoTo cboNameSearch_AfterUpdate_Err
If (IsNull(Screen.ActiveControl)) Then
Exit Sub
End If
On Error Resume Next
If (Form.Dirty) Then
DoCmd.RunCommand acCmdSaveRecord
End If
If (MacroError.Number <> 0) Then
Beep
MsgBox MacroError.Description, vbOKOnly, ""
Exit Sub
End If
On Error GoTo 0
TempVars.Add "ActiveControlValue", "[Screen].[ActiveControl]"
If (CurrentProject.IsTrusted) Then
Screen.ActiveControl = Null
End If
If (Form.FilterOn) Then
DoCmd.RunCommand acCmdRemoveFilterSort
End If
DoCmd.SearchForRecord acForm, Forms![Marketing Targets]!MarketingTargetsSubform.Form, acFirst, "[Contact ID]=" & TempVars!ActiveControlValue
TempVars.Remove "ActiveControlValue"
cboNameSearch_AfterUpdate_Exit:
Exit Sub
cboNameSearch_AfterUpdate_Err:
MsgBox Error$
Resume cboNameSearch_AfterUpdate_Exit
End Sub
In the body of the form I have a subform with the control name "MarketingTargetsSubform", and the main form's name is "Marketing Targets". I'm trying to use a simple doCmd.GoToRecord, but I keep getting the error "An expression you entered is the wrong data type for one of the arguments", and then in the debugger it jumps to the key line:
Code:
DoCmd.SearchForRecord acForm, Forms![Marketing Targets]!MarketingTargetsSubform.Form, acFirst, "[Contact ID]=" & TempVars!ActiveControlValue
The subform is not linked to the main form in any way (no child or master fields)
I've checked syntax and googled as much as I can on the topic. Any suggestions?