JamieRhysEdwards
New member
- Local time
- Today, 11:20
- Joined
- Mar 26, 2022
- Messages
- 27
Hi All,
Bit of a weird one. I'm trying to make a "Go To Record" Combo box. I'm using the Asset Database template as reference and in their Contact Details form, it has the same thing (which works if using macro's). However, when I convert it to VBA and copy the code, I get the following error:
This is the code in the template:
Mine is this for now:
Not too dissimilar, however, I saw this error initially in my code, I then converted the macro on the template to VBA and as mentioned above, got the error. How would I fix this given that Microsoft uses it in their macro (and access seems ok with this) but when it's converted to VBA it doesn't like it?
Thanks!
Bit of a weird one. I'm trying to make a "Go To Record" Combo box. I'm using the Asset Database template as reference and in their Contact Details form, it has the same thing (which works if using macro's). However, when I convert it to VBA and copy the code, I get the following error:
Code:
Run-time error '32538':
TempVars can only store data. They cannot store objects.
This is the code in the template:
Code:
Private Sub cboGoToContact_AfterUpdate()
On Error GoTo cboGoToContact_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 ' This is the offending line!
If (CurrentProject.IsTrusted) Then
Screen.ActiveControl = Null
End If
If (Form.FilterOn) Then
DoCmd.RunCommand acCmdRemoveFilterSort
End If
DoCmd.SearchForRecord , "", acFirst, "[ID]=" & TempVars!ActiveControlValue
TempVars.Remove "ActiveControlValue"
cboGoToContact_AfterUpdate_Exit:
Exit Sub
cboGoToContact_AfterUpdate_Err:
MsgBox Error$
Resume cboGoToContact_AfterUpdate_Exit
End Sub
Mine is this for now:
Code:
If (IsNull(Screen.ActiveControl)) Then
Exit Sub
End If
On Error Resume Next
If (Form.Dirty) Then
Call 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
DoCmd.SearchForRecord , "", acFirst, "[ID]=" & TempVars!ActiveControlValue
Not too dissimilar, however, I saw this error initially in my code, I then converted the macro on the template to VBA and as mentioned above, got the error. How would I fix this given that Microsoft uses it in their macro (and access seems ok with this) but when it's converted to VBA it doesn't like it?
Thanks!