colinmcewan
New member
- Local time
- Today, 15:07
- Joined
- Apr 13, 2011
- Messages
- 5
Hi. I am a novice and would appreciate a helpimg hand.
I have customised the contacts database and now want the ability to print a single label using a button on the contact details form.
Having searched the web, I found a very helpful article by Susan Harkins which explained precisely how to do it. Snag is, when I hit the button, ALL the contacts are printed.
I suspect that it is something to do with the fact that the primary key for each contact is an automatically generated number rather than a string - but I could be way off here.
The code she gave was a follows
Private Sub cmdPrintLabel_Click()
'Send customer data to label report
Dim str As String
On Error GoTo ErrHandler
If IsNull(Me!CustomerID) Then
MsgBox "Can't print an unsaved record", _
vbOKOnly, "Error"
Exit Sub
End If
str = "CustomerID = '" & Me!CustomerID & "'"
Debug.Print str
'Open report in Print Preview.
DoCmd.OpenReport "rptCustomerLabels", acViewPreview, , str
Exit Sub
ErrHandler:
MsgBox Err.Number & ": " _
& Err.Description, vbOKOnly, "Error"
End Sub
Can anyone help me out ?
Many thanks
Colin
I have customised the contacts database and now want the ability to print a single label using a button on the contact details form.
Having searched the web, I found a very helpful article by Susan Harkins which explained precisely how to do it. Snag is, when I hit the button, ALL the contacts are printed.
I suspect that it is something to do with the fact that the primary key for each contact is an automatically generated number rather than a string - but I could be way off here.
The code she gave was a follows
Private Sub cmdPrintLabel_Click()
'Send customer data to label report
Dim str As String
On Error GoTo ErrHandler
If IsNull(Me!CustomerID) Then
MsgBox "Can't print an unsaved record", _
vbOKOnly, "Error"
Exit Sub
End If
str = "CustomerID = '" & Me!CustomerID & "'"
Debug.Print str
'Open report in Print Preview.
DoCmd.OpenReport "rptCustomerLabels", acViewPreview, , str
Exit Sub
ErrHandler:
MsgBox Err.Number & ": " _
& Err.Description, vbOKOnly, "Error"
End Sub
Can anyone help me out ?
Many thanks
Colin