Second Report not printing - whats wrong with the VBA I have??????

B

Billp

Hi,

I have a control that should allow two reports to be printed.
They are basically the same report - different colours and a reprint stamp
situated in another location. Via a hidden form and global variable the two
reports should
print and use the same query as the basies. What I am getting is the first
printing then the second sort of starts and then dies with no result. The
following VBA is used. First one is behind the control on the form.
The second two are what is behind the reports.
Have I gone about this the wrong way?

Dim stDocName As String
Dim stDocName_Blue As String
Dim stWcnum As String
Dim intPrint As Integer
Dim intPrintResp As Integer
Dim strWorksNo As String
Dim strsql As String
Dim rst As DAO.Recordset

stWcnum = Me!cboWorksNumberSelect
Forms![frmGlobalVariables]![Text0] = stWcnum
stDocName = "rptWorksCards"
stDocName_Blue = "rptWorksCards_Blue"
'print the green card
DoCmd.OpenReport stDocName, acNormal
'print the blue card
MsgBox "Printing Blue Card"
DoCmd.OpenReport stDocName_Blue, acNormal


Set rst = CurrentDb.OpenRecordset("tblWorksCard", dbOpenDynaset)
strWorksNo = Forms![frmGlobalVariables]![Text0]
strsql = "[Works_Number] = '" & strWorksNo & "'" 'this is text
rst.FindFirst strsql

If rst![CardPrinted].Value = False Then
intPrint = MsgBox("Did both Works Card pages print successfully?", _
vbYesNo + vbQuestion, "Print Status")
Select Case intPrint
Case vbYes 'Successful print. Mark the
'record accordingly.
rst.Edit
rst![CardPrinted].Value = True
rst.Update
Case vbNo 'Print problem.
'DON'T mark the record
intPrintResp = MsgBox("Please correct the problem " _
& "and try again .", vbOKOnly + vbExclamation, "Print Status")
End Select
End If

rst.Close
Set rst = Nothing

**********************************************************************

Report number 1

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)

Dim booPrinted As Boolean
Dim strsql As String
Dim strWorksNumber As String
Dim rst As DAO.Recordset

'Look up the Orders Table and determine if the logical field
'booPrinted is true. If so, the user has previously specified
'that the Works Card was successfully printed. The card will
'require the "REPRINT" labels to be visible.
'If the field is false, the labels remain not visible.

strWorksNumber = Me!txtWorks_Number

strsql = "SELECT tblWorksCard.CardPrinted "
strsql = strsql & "FROM tblWorksCard "
strsql = strsql & "WHERE (((tblWorksCard.Works_Number) = '"
strsql = strsql & strWorksNumber & "'));"

Set rst = CurrentDb.OpenRecordset(strsql)
rst.MoveFirst
booPrinted = rst!CardPrinted.Value

If booPrinted Then
Me!oleReprint.Visible = True

Else
Me!oleReprint.Visible = False

End If

rst.Close
Set rst = Nothing


End Sub

*************************************************************************
Report Number 2
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Dim booPrinted As Boolean
Dim strsql As String
Dim strWorksNumber As String
Dim rst1 As DAO.Recordset

'Look up the Orders Table and determine if the logical field
'booPrinted is true. If so, the user has previously specified
'that the Works Card was successfully printed. The card will
'require the "REPRINT" labels to be visible.
'If the field is false, the labels remain not visible.

strWorksNumber = Me!txtWorks_Number

strsql = "SELECT tblWorksCard.CardPrinted "
strsql = strsql & "FROM tblWorksCard "
strsql = strsql & "WHERE (((tblWorksCard.Works_Number) = '"
strsql = strsql & strWorksNumber & "'));"

Set rst1 = CurrentDb.OpenRecordset(strsql)
rst1.MoveFirst
booPrinted = rst1!CardPrinted.Value

If booPrinted Then

Me!oleReprint1.Visible = True
Else

Me!oleReprint1.Visible = False
End If

rst1.Close
Set rst1 = Nothing
End Sub


What would be the cause of the second report not printing?

Originally they were on the same A3 size report but printed as two pages.
Now I want them as two separate reports.
Don’t know what to do.
Any help and advice appreciated and I than you in advance.
 
B

Billp

And the answer is - a spelling mistake and a field that need to be changed on
the form.
Me!txtWorks_Number did not exist on the second form but was text13


arrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr

Billp said:
Hi,

I have a control that should allow two reports to be printed.
They are basically the same report - different colours and a reprint stamp
situated in another location. Via a hidden form and global variable the two
reports should
print and use the same query as the basies. What I am getting is the first
printing then the second sort of starts and then dies with no result. The
following VBA is used. First one is behind the control on the form.
The second two are what is behind the reports.
Have I gone about this the wrong way?

Dim stDocName As String
Dim stDocName_Blue As String
Dim stWcnum As String
Dim intPrint As Integer
Dim intPrintResp As Integer
Dim strWorksNo As String
Dim strsql As String
Dim rst As DAO.Recordset

stWcnum = Me!cboWorksNumberSelect
Forms![frmGlobalVariables]![Text0] = stWcnum
stDocName = "rptWorksCards"
stDocName_Blue = "rptWorksCards_Blue"
'print the green card
DoCmd.OpenReport stDocName, acNormal
'print the blue card
MsgBox "Printing Blue Card"
DoCmd.OpenReport stDocName_Blue, acNormal


Set rst = CurrentDb.OpenRecordset("tblWorksCard", dbOpenDynaset)
strWorksNo = Forms![frmGlobalVariables]![Text0]
strsql = "[Works_Number] = '" & strWorksNo & "'" 'this is text
rst.FindFirst strsql

If rst![CardPrinted].Value = False Then
intPrint = MsgBox("Did both Works Card pages print successfully?", _
vbYesNo + vbQuestion, "Print Status")
Select Case intPrint
Case vbYes 'Successful print. Mark the
'record accordingly.
rst.Edit
rst![CardPrinted].Value = True
rst.Update
Case vbNo 'Print problem.
'DON'T mark the record
intPrintResp = MsgBox("Please correct the problem " _
& "and try again .", vbOKOnly + vbExclamation, "Print Status")
End Select
End If

rst.Close
Set rst = Nothing

**********************************************************************

Report number 1

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)

Dim booPrinted As Boolean
Dim strsql As String
Dim strWorksNumber As String
Dim rst As DAO.Recordset

'Look up the Orders Table and determine if the logical field
'booPrinted is true. If so, the user has previously specified
'that the Works Card was successfully printed. The card will
'require the "REPRINT" labels to be visible.
'If the field is false, the labels remain not visible.

strWorksNumber = Me!txtWorks_Number

strsql = "SELECT tblWorksCard.CardPrinted "
strsql = strsql & "FROM tblWorksCard "
strsql = strsql & "WHERE (((tblWorksCard.Works_Number) = '"
strsql = strsql & strWorksNumber & "'));"

Set rst = CurrentDb.OpenRecordset(strsql)
rst.MoveFirst
booPrinted = rst!CardPrinted.Value

If booPrinted Then
Me!oleReprint.Visible = True

Else
Me!oleReprint.Visible = False

End If

rst.Close
Set rst = Nothing


End Sub

*************************************************************************
Report Number 2
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Dim booPrinted As Boolean
Dim strsql As String
Dim strWorksNumber As String
Dim rst1 As DAO.Recordset

'Look up the Orders Table and determine if the logical field
'booPrinted is true. If so, the user has previously specified
'that the Works Card was successfully printed. The card will
'require the "REPRINT" labels to be visible.
'If the field is false, the labels remain not visible.

strWorksNumber = Me!txtWorks_Number

strsql = "SELECT tblWorksCard.CardPrinted "
strsql = strsql & "FROM tblWorksCard "
strsql = strsql & "WHERE (((tblWorksCard.Works_Number) = '"
strsql = strsql & strWorksNumber & "'));"

Set rst1 = CurrentDb.OpenRecordset(strsql)
rst1.MoveFirst
booPrinted = rst1!CardPrinted.Value

If booPrinted Then

Me!oleReprint1.Visible = True
Else

Me!oleReprint1.Visible = False
End If

rst1.Close
Set rst1 = Nothing
End Sub


What would be the cause of the second report not printing?

Originally they were on the same A3 size report but printed as two pages.
Now I want them as two separate reports.
Don’t know what to do.
Any help and advice appreciated and I than you in advance.
 

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