Report code

A

A Moloney

Hi
I have the below code that runs off a command button on
my form. It prints two copies of the report which is fine
but it is actually applying itself to each record so when
i select the command it prints this report for every
record. Is there any way to specify that the report only
prints based on the current/selected record that is in
view?
any help appreciated.

Private Sub Print10b_Click()
On Error GoTo Err_Print10b_Click

Dim stDocName As String

stDocName = "10bConfirmation"
DoCmd.OpenReport stDocName, acNormal, , strWhere
DoCmd.OpenReport stDocName, acNormal, , strWhere


Exit_Print10b_Click:
Exit Sub

Err_Print10b_Click:
MsgBox Err.Description
Resume Exit_Print10b_Click

End Sub
 
D

Duane Hookom

You would add code for a "where" clause
Private Sub Print10b_Click()
On Error GoTo Err_Print10b_Click
Dim strWhere as String
Dim stDocName As String
strWhere = "[NumericID]=" & Me.txtNumericID

stDocName = "10bConfirmation"
DoCmd.OpenReport stDocName, acNormal, , strWhere
DoCmd.OpenReport stDocName, acNormal, , strWhere


Exit_Print10b_Click:
Exit Sub

Err_Print10b_Click:
MsgBox Err.Description
Resume Exit_Print10b_Click

End Sub
 
M

Marshall Barton

A said:
I have the below code that runs off a command button on
my form. It prints two copies of the report which is fine
but it is actually applying itself to each record so when
i select the command it prints this report for every
record. Is there any way to specify that the report only
prints based on the current/selected record that is in
view?
any help appreciated.

Private Sub Print10b_Click()
On Error GoTo Err_Print10b_Click

Dim stDocName As String

stDocName = "10bConfirmation"
DoCmd.OpenReport stDocName, acNormal, , strWhere
DoCmd.OpenReport stDocName, acNormal, , strWhere


Exit_Print10b_Click:
Exit Sub

Err_Print10b_Click:
MsgBox Err.Description
Resume Exit_Print10b_Click

End Sub


You never specified a filter expression for the
WhereCondition argument. Add a line of code something like:

strWhere = "keyfield = " & keytextbox
 

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

Similar Threads


Top