Print a Membership Record from a Form

P

PR

I want to be able to print a membership record from a form...

I have a form with details of a member on it... I want to print a report
from this form with membership details on it...

I have the report and it works... I have the form and it works...

When I go to print the form using a button... it defaults to the first
record...

Below is the code I am using on the button... but the focus does not stay
with the current record...

Private Sub cmdPrintMembershipCardW_Click()
On Error GoTo Err_cmdPrintMembershipCardW_Click
Dim stFilter As String
stDocName = "PK_MembershipNo = " & Me.PK_MembershipNo

' Save record to allow it to be read for the report
DoCmd.RunCommand acCmdSaveRecord
DoCmd.OpenReport "rpt_membership_card_W", acPreview

Exit_cmdPrintMembershipCardW_Click:
Exit Sub

Err_cmdPrintMembershipCardW_Click:
MsgBox Err.Description
Resume Exit_cmdPrintMembershipCardW_Click
End Sub

Can anyone help...
 
F

fredg

I want to be able to print a membership record from a form...

I have a form with details of a member on it... I want to print a report
from this form with membership details on it...

I have the report and it works... I have the form and it works...

When I go to print the form using a button... it defaults to the first
record...

Below is the code I am using on the button... but the focus does not stay
with the current record...

Private Sub cmdPrintMembershipCardW_Click()
On Error GoTo Err_cmdPrintMembershipCardW_Click
Dim stFilter As String
stDocName = "PK_MembershipNo = " & Me.PK_MembershipNo

' Save record to allow it to be read for the report
DoCmd.RunCommand acCmdSaveRecord
DoCmd.OpenReport "rpt_membership_card_W", acPreview

Exit_cmdPrintMembershipCardW_Click:
Exit Sub

Err_cmdPrintMembershipCardW_Click:
MsgBox Err.Description
Resume Exit_cmdPrintMembershipCardW_Click
End Sub

Can anyone help...

If you are going to use variables you must DIM both of them, then give
them a value.
Then you have to use them in the code. You didn't use the Where clause
variable at all!!

Private Sub cmdPrintMembershipCardW_Click()
On Error GoTo Err_cmdPrintMembershipCardW_Click
Dim stDocName as String
Dim stFilter As String
stDocName = "rpt_membership_card_W"
stFilter = "PK_MembershipNo = " & Me.PK_MembershipNo

' Save record to allow it to be read for the report
DoCmd.RunCommand acCmdSaveRecord
DoCmd.OpenReport stDocName, acViewPreview, , stFilter

Exit_cmdPrintMembershipCardW_Click:
Exit Sub

Err_cmdPrintMembershipCardW_Click:
MsgBox Err.Description
Resume Exit_cmdPrintMembershipCardW_Click
End Sub
 
P

PR

Fred,
I have done what you suggest, but now get a 'data type mismatch in criteria
expression' where would this be?

Paul.
 
P

PR

Fred, I have change part of the code to
= "[PK_MembershipNo]=" & "'" & Me![PK_MembershipNo] & "'"

and this works now...
thanks you very much for your help...

Paul
 
F

fredg

Fred, I have change part of the code to
= "[PK_MembershipNo]=" & "'" & Me![PK_MembershipNo] & "'"

and this works now...
thanks you very much for your help...

Paul
fredg said:
If you are going to use variables you must DIM both of them, then give
them a value.
Then you have to use them in the code. You didn't use the Where clause
variable at all!!

Private Sub cmdPrintMembershipCardW_Click()
On Error GoTo Err_cmdPrintMembershipCardW_Click
Dim stDocName as String
Dim stFilter As String
stDocName = "rpt_membership_card_W"
stFilter = "PK_MembershipNo = " & Me.PK_MembershipNo

' Save record to allow it to be read for the report
DoCmd.RunCommand acCmdSaveRecord
DoCmd.OpenReport stDocName, acViewPreview, , stFilter

Exit_cmdPrintMembershipCardW_Click:
Exit Sub

Err_cmdPrintMembershipCardW_Click:
MsgBox Err.Description
Resume Exit_cmdPrintMembershipCardW_Click
End Sub

Evidently your Prime Key is a text datatype field and not Number
datatype.
A bit simpler syntax would be:
stFilter = "[PK_MembershipNo]= '" & Me![PK_MembershipNo] & "'"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top