Report code

  • Thread starter Thread starter A Moloney
  • Start date Start date
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
 
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
 
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

Multiple Reports to use only 1 Query 1
Stop print more than one copy of a report 1
Help with code 3
Specific report 2
Tidying my report 2
Button Coding for Reports 2
Printing Multiple Reports 6
Help!! 3

Back
Top