John O'Malvern
Member
- Local time
- Today, 23:01
- Joined
- Mar 25, 2024
- Messages
- 61
I'm using this code to open a form in print preview:
but it throws up this error:
and when I click on debug, it highlights [in yellow] the line with 'Contact ID' (I inherited this db with spaces in the fieldnames
)
There is no |1 in the highlighted line, and I've no idea where else to find it. (must be a typo)
I'm not good at VBA, the code is from 'Microsoft Access Tips for Casual Users'
Any suggestions on what I'm doing wrong, please?
Thanks,
John
Code:
Private Sub cmdPrint_Click()
Dim strWhere As String
If Me.Dirty Then 'Save any edits.
Me.Dirty = False
End If
If Me.NewRecord Then 'Check there is a record to print
MsgBox "Select a record to print"
Else
strWhere = "[Contact ID] = " & Me.[Contact ID]
DoCmd.OpenReport "Associate_MembershipCard_FormGDPRSel_frmNewAssoc", acViewPreview, , strWhere
End If
End Sub
but it throws up this error:
and when I click on debug, it highlights [in yellow] the line with 'Contact ID' (I inherited this db with spaces in the fieldnames

There is no |1 in the highlighted line, and I've no idea where else to find it. (must be a typo)
I'm not good at VBA, the code is from 'Microsoft Access Tips for Casual Users'
Any suggestions on what I'm doing wrong, please?
Thanks,
John