Hi all,
Thank you for all your help.
Here is the final solution:
Code:
Sub Go_Print_Badges(intPrintType, strCriteria, str_Mode, str_Size)
Dim nJobNo As Integer
Dim nSequenceNo As Integer
Dim rstSpool As Recordset
Dim Records As Recordset
Dim nRecordNumber As Integer
Dim sSQL As String
Dim strDirectory As String
'-----------------------------
'Comment out/remove the msgbox after debug complete
'MsgBox "intPrintType = " & intPrintType & vbCrLf & _
' "strCriteria = " & strCriteria & vbCrLf & _
' "str_Mode = " & str_Mode & vbCrLf & _
' "str_Size = " & str_Size & vbCrLf
'-----------------------------
If bln_Use_Print_Spooler Then
'Mid(strCriteria, 20) = "Visitor_ID"
DoCmd.Echo True, "Sending to Spooler..."
sSQL = "SELECT dbo_Tbl_Visitors.[Visitor_ID] AS [Visitor ID], dbo_Tbl_Visitors.[Show ID], [Tbl_Visitors Flags].[Type ID], [Tbl_Visitors Flags].[Status ID]" & _
" FROM dbo_Tbl_Visitors INNER JOIN [Tbl_Visitors Flags]" & _
" ON dbo_Tbl_Visitors.[Visitor_ID] = [Tbl_Visitors Flags].[Visitor ID]" & _
" WHERE " & strCriteria & ";"
'sSQL = "SELECT [Visitor ID], [Directory], [Type ID]" & _
'sSQL = sSQL & " FROM (Tbl_Visitors INNER JOIN [Tbl_Workstation Settings]"
'sSQL = sSQL & " ON Tbl_Visitors.[Show ID] = [Tbl_Workstation Settings].[Show ID]) INNER JOIN [Tbl_Visitors Flags] ON Tbl_Visitors.[Visitor ID] = [Tbl_Visitors Flags].[Visitor ID]"
'sSQL = sSQL & " WHERE " & strCriteria & ";"
'Debug.Print sSQL
Set Records = CurrentDb.OpenRecordset(sSQL, , dbForwardOnly)
'Check for records
If Not Records.BOF And Not Records.EOF Then
Records.MoveLast
Records.MoveFirst
'---------------
'Comment out later
'MsgBox "There are " & Records.RecordCount & " records to process"
'---------------
sSQL = "SELECT Max(JobNo) As MaxJobNo FROM RegPrintQueue" 'Yaroslav's check for current JobNo
Set rstSpool = CurrentDb.OpenRecordset(sSQL, , dbForwardOnly)
rstSpool.MoveFirst
If nJobNo = Null Then
nJobNo = 1
Else
nJobNo = rstSpool!MaxJobNo + 1 'Increment to next available JobNo
End If
rstSpool.Close
'sSQL = "SELECT Max(SequenceNo) As MaxSequenceNo FROM RegPrintQueue" 'Yaroslav's check for current SequenceNo
'Set rstSpool = CurrentDb.OpenRecordset(sSQL, , dbForwardOnly)
'rstSpool.MoveFirst
'nSequenceNo = rstSpool!MaxSequenceNo + 1 'Increment to next available JobNo
'rstSpool.Close
' Open Dynamic Recordset for Spooler.mdb
sSQL = "SELECT JobNo, SequenceNo, [Database], RecordNumber, SubmittedTimestamp"
sSQL = sSQL & " FROM RegPrintQueue"
Set rstSpool = CurrentDb.OpenRecordset(sSQL, , dbAppendOnly)
nSequenceNo = 1
Do Until Records.EOF
nRecordNumber = Records.Fields("[Visitor ID]")
strDirectory = strSystem_Directory 'Records.Fields("Directory")
rstSpool.AddNew
rstSpool!JobNo = nJobNo
rstSpool!SequenceNo = nSequenceNo
rstSpool!Database = strDirectory 'MDB Directory
rstSpool!RecordNumber = nRecordNumber 'Visitor ID
rstSpool!SubmittedTimestamp = Now()
rstSpool.Update
'---------------------------------------------
'This is an alternate way to insert records into a table
' sSQL = "INSERT INTO RegPrintQueue ( JobNo, SequenceNo, [Database], RecordNumber, SubmittedTimestamp )"
' sSQL = sSQL & " VALUES (" & nJobNo & ", " & nSequenceNo & ", 'S:', " & nRecordNumber & ", #" & Now() & "#;"
' ' Debug.Print sSQL
' CurrentDb.Execute sSQL, dbFailOnError
'---------------------------------------------
DoCmd.Echo True, "Printing Badge..."
nSequenceNo = nSequenceNo + 1
Records.MoveNext 'The "Records" recordset is the source
Loop
rstSpool.Close
Records.Close
Set rstSpool = Nothing
Set Records = Nothing
End If
Else
Select Case str_Mode
Case "BATCH"
DoCmd.OpenReport "Batch Print Badge " & str_Size, intPrintType, , strCriteria
Case "SINGLE"
DoCmd.OpenReport "Badge " & str_Size, intPrintType, , strCriteria
End Select
End If
End Sub
It works as desired, but now I have come up with another problem to do with the same function
I am trying to save and print my record. Once it saves, it goes to the function above.
Here is the save function:
Code:
Public Sub Save_Record(lngVisitor_ID As Long, Optional ByVal boPrint As Boolean = True)
Const Duplicate_Error = 3022
On Error GoTo Save_Record_Err
Dim intDemographics As Integer
Dim boDemographic As Boolean
Dim strSearch_Criteria As String
Dim varOptions As Variant
Dim intOption As Integer
Dim intAnswer As Integer
Dim strMessage_Text As String
Dim strMessage_Title As String
Dim varField_Format As Variant
Dim strExtra_Criteria As String
Dim boPrint_Badge As Boolean
Dim strSql As String
Dim SubForm As Form
If IsLoaded("Frm_Input") Then
With Forms!Frm_Input
If Not Check_Details() Then Exit Sub
If boPrint Then
If boOnSite And boNew_Visitor Then
strMessage_Text = "Do you want to print a badge for this person?@" & _
"'OK' will update the database and print a badge;" & vbCrLf & _
"'Cancel' will allow you to make further changes to this record.@"
strMessage_Title = "Save and Print Badge for Visitor ID " & ![Visitor ID]
Beep
intAnswer = MsgBox(strMessage_Text, vbQuestion + vbOKCancel, strMessage_Title)
If intAnswer = vbOK Then intAnswer = vbYes
Else
strMessage_Text = "Do you want to print a badge for this person?@" & _
"'Yes' will update the database and print a badge;" & vbCrLf & _
"'No' will update the data without printing a badge;" & vbCrLf & _
"'Cancel' allows you to make changes to this screen before updating the data.@"
strMessage_Title = "Update to Visitor ID " & ![Visitor ID]
Beep
intAnswer = MsgBox(strMessage_Text, vbQuestion + vbYesNoCancel, strMessage_Title)
End If
Else
intAnswer = vbNo
End If
DoCmd.Hourglass True
If intAnswer <> vbCancel Then
rstVisitors.FindFirst "[Visitor ID] = " & ![Visitor ID]
If rstVisitors.NoMatch Then
![Badge ID] = Badge_ID_Rule(!Surname, ![Visitor ID])
'New visitor record
rstVisitors.AddNew
rstVisitors![Show ID] = lngShow_ID
rstVisitors![Visitor ID] = ![Visitor ID]
rstVisitors![Badge ID] = ![Badge ID]
Create_Flag
Else
'Existing visitor record
If boNew_Visitor Then
Do
Get_Next_BadgeID
rstVisitors.FindFirst "[Visitor ID] = " & ![Visitor ID]
Loop Until rstVisitors.NoMatch
![Badge ID] = Badge_ID_Rule(!Surname, ![Visitor ID])
'New visitor record
rstVisitors.AddNew
rstVisitors![Show ID] = lngShow_ID
rstVisitors![Visitor ID] = ![Visitor ID]
rstVisitors![Badge ID] = ![Badge ID]
Create_Flag
Else
rstVisitors.Edit
End If
rstFlags.FindFirst "[Visitor ID] = " & ![Visitor ID]
If rstFlags.NoMatch Then
Create_Flag
Else
rstFlags.Edit
rstFlags![Updated] = Now()
End If
If intAnswer = vbYes And boOnSite And ![Visitor Status] = igcPreReg Then
![Visitor Status] = igcPreRegAttendee
End If
If DateDiff("d", rstSettings![Start of Show], Date) >= 0 Then
'Keep Visitor Entry records up-to-date
CurrentDb.Execute "UPDATE dbo_Tbl_Visitor_Entry" & _
" SET Visitor_Type = " & ![Visitor Type] & _
" WHERE Show_ID = " & lngShow_ID & _
" AND Barcode = '" & ![Badge ID] & "'" & _
" AND Visitor_Type <> " & ![Visitor Type], dbFailOnError
End If
End If
rstVisitors![Title] = ![Title]
rstVisitors![Forename] = ![Forename]
rstVisitors![Surname] = ![Surname]
rstVisitors![Job Title] = ![Job Title]
rstVisitors![Department] = ![Department]
rstVisitors![Company] = ![Company]
rstVisitors![Company2] = ![Company2]
rstVisitors![Post Code] = ![Post Code]
rstVisitors![Address Line 0] = ![Address 0]
rstVisitors![Address Line 1] = ![Address 1]
rstVisitors![Address Line 2] = ![Address 2]
rstVisitors![Address Line 3] = ![Address 3]
rstVisitors![Address Line 4] = ![Address 4]
rstVisitors![Country Name] = ![Country]
rstVisitors![Phone No] = ![Phone]
rstVisitors![Fax No] = ![Fax]
rstVisitors![E-Mail] = ![E-Mail]
rstVisitors![Mobile_No] = ![Mobile_No]
rstFlags![Type ID] = ![Visitor Type]
rstFlags![Status ID] = ![Visitor Status]
'rstFlags![Purchasing Authority] = Val(Nz(![Purchasing Authority], 0))
rstFlags![Data Protection] = Nz(![Data Protection Act], False)
rstFlags![Data Protection 2] = Nz(![Data Protection Act2], False)
rstFlags![Source Code] = ![Source Code]
rstVisitors![Mailing Contact ID] = ![cmbMailingContactID]
rstVisitors![DP_codes] = ![DP_codes]
rstVisitors![Analysis_Codes] = ![Analysis_Codes]
rstVisitors![Media_Type] = ![Media_Type]
rstVisitors![Reg_Method] = ![Reg_Method]
rstVisitors![A001] = ![A001]
rstVisitors![A002] = ![A002]
rstVisitors![A003] = ![A003]
rstVisitors![A004] = ![A004]
rstVisitors![A005] = ![A005]
rstVisitors![A006] = ![A006]
rstVisitors![A007] = ![A007]
rstVisitors![A008] = ![A008]
rstVisitors![A009] = ![A009]
rstVisitors![A010] = ![A010]
'rstFlags![Seminar Codes] = ![Seminar Codes]
rstVisitors![Session Codes] = ![Session_Codes]
rstFlags![ABC Question] = ![ABC Question]
rstFlags![Payment Amount] = varPaymentAmount
rstFlags![Payment Method ID] = varPaymentMethodID
rstFlags![Payment Status ID] = varPaymentStatusID
rstFlags![Payment Date] = varPaymentDate
rstFlags![Dietary Requirements] = varDietaryRequirements
rstFlags![Special Requirements] = varSpecialRequirements
'Photo Save
Dim str_badge_id As String
str_badge_id = ![Badge ID]
!ctl_Image.SaveToFile strSystem_Directory & "\photos\" & str_badge_id & ".jpg"
If intAnswer = vbYes Then
rstFlags![Badge Printed] = Now()
rstFlags![Badge Print By] = GetCurrentUser()
End If
rstVisitors.Update
'Check Mailing Contact
If ![cmbMailingContactID] = ![Visitor ID] Then
![cmbMailingContactID].Requery
End If
'Check Postal Town
If boPostalTownLearning Then
If ![Address 3].ListIndex = -1 And Not IsNull(![Address 3]) And Not IsNull(![Address 4]) Then
CurrentDb.Execute "INSERT INTO dbo_Lup_Tbl_Postal_Towns (Town, Region_Code) " & _
"VALUES (""" & Trim(![Address 3]) & """,""" & ![Address 4].Column(1) & """)", dbFailOnError
![Address 3].Requery
End If
End If
'Check New Company Name
If !Company.ListIndex = -1 And Not IsNull(!Company) Then
CurrentDb.Execute "INSERT INTO dbo_Tbl_Companies (Show_ID, Company_Name, Company_Name_2) " & _
"VALUES (" & lngShow_ID & ",""" & Trim(!Company) & """,""" & Trim(!Company2) & """)", dbFailOnError
!Company.Requery
End If
'Save Flags record
rstFlags.Update
'Delete demographics and re-create
CurrentDb.Execute "DELETE FROM dbo_Tbl_Visitors_Demographics" & _
" WHERE Show_ID = " & lngShow_ID & _
" AND Visitor_ID = " & ![Visitor ID], dbFailOnError
Set SubForm = !SubDemographics.Form
For intDemographics = 1 To intDemographicFieldCount
boDemographic = False
If Not IsNull(SubForm("Multiple " & intDemographics)) Then
If SubForm("Multiple " & intDemographics) Then
If SubForm("Option Text " & intDemographics).Visible Then
boDemographic = True
varOptions = SubForm("Option Text " & intDemographics)
End If
Else
If SubForm("Option Combo " & intDemographics).Visible Then
boDemographic = True
varOptions = SubForm("Option Combo " & intDemographics)
End If
End If
If boDemographic Then
If Not IsNull(varOptions) Then
Do Until Len(varOptions) = 0
intOption = InStr(varOptions, " ")
If intOption = 0 Then
intOption = Val(varOptions)
varOptions = ""
Else
intOption = Val(Left(varOptions, InStr(varOptions, " ") - 1))
varOptions = Trim(Right(varOptions, Len(varOptions) - InStr(varOptions, " ")))
End If
rstDemographics.AddNew
rstDemographics![Show ID] = lngShow_ID
rstDemographics![Visitor ID] = ![Visitor ID]
rstDemographics![Category] = intDemographics
rstDemographics![Option] = intOption
rstDemographics.Update
Loop
End If
End If
End If
Next intDemographics
Set SubForm = Nothing
rstVisitors.Requery
rstFlags.Requery
rstDemographics.Requery
If intAnswer = vbYes Then
If Not boOnSite Then
If ![Visitor Type] <> igcExhibitor And rstSettings![Visitor Letter] = -1 Then
DoCmd.OpenReport "Rpt_" & Show_Name() & " Visitor Letter", acViewNormal, , "[Show ID] = " & lngShow_ID & " And [Visitor ID] = " & ![Visitor ID]
ElseIf ![Visitor Type] = igcExhibitor And rstSettings![Exhibitor Letter] = -1 Then
DoCmd.OpenReport "Rpt_" & Show_Name() & " Exhibitor Letter", acViewNormal, , "[Show ID] = " & lngShow_ID & " And [Visitor ID] = " & ![Visitor ID]
End If
End If
Go_Print_Badges acViewNormal, "[Show ID] = " & lngShow_ID & " And [Visitor ID] = " & ![Visitor ID], "SINGLE", REGISTRATION_BADGE_SIZE
End If
If boOnSite And intAnswer = vbYes Then
'Record date and time of attendance
strSql = "INSERT INTO dbo_Tbl_Visitor_Entry (Show_ID, Badge_ID, Barcode, Date_And_Time, Visitor_Type) " & _
"VALUES (" & lngShow_ID & "," & ![Visitor ID] & ",'" & ![Badge ID] & "', Now()," & ![Visitor Type] & ")"
CurrentDb.Execute strSql, dbFailOnError
End If
' add the updated record to the OLR queue
If bln_REGISTRATION_USE_QUEUE = True Then
Dim rst_OLR_Queue As Recordset
Set rst_OLR_Queue = CurrentDb().OpenRecordset("t_registration_queue", , dbAppendOnly)
rst_OLR_Queue.AddNew
rst_OLR_Queue!Visitor_ID = ![Visitor ID]
rst_OLR_Queue!added_timestamp = Now()
rst_OLR_Queue!pending_flag = True
rst_OLR_Queue.Update
End If
![AddedMessage] = "Visitor " & ![Visitor ID] & " saved" & IIf(intAnswer = vbYes, " and badge printed.", ".")
If boPrint Then
If ![Visitor Type] = igcExhibitor And Not boOnSite Then
boNew_Visitor = True
![Visitor ID] = lngVisitor_ID
![Badge ID] = Null
![Title] = Null
![Forename] = Null
![Surname] = Null
![Job Title] = Null
![E-Mail] = Null
![chkMailingContact] = False
ClearDemographics
![Title].SetFocus
Get_Next_BadgeID
.Repaint
Else
Clear_Screen
End If
boSaved_Record = False
Else
boSaved_Record = True
End If
End If
End With
End If
DoCmd.Hourglass False
Exit Sub
Save_Record_Err:
If Err = Duplicate_Error Then Resume Next
If Err = ReportCancelled_Error Then
intAnswer = vbNo
boPrint = False
Resume Next
End If
Debug.Print strSql
DoCmd.Hourglass False
MsgBox Err & " : " & Err.Description, vbCritical, "Error in Sub Save_Record"
End Sub
This function causes a parameter expected error which requires 1
Code:
If intAnswer = vbYes Then
If Not boOnSite Then
If ![Visitor Type] <> igcExhibitor And rstSettings![Visitor Letter] = -1 Then
DoCmd.OpenReport "Rpt_" & Show_Name() & " Visitor Letter", acViewNormal, , "[Show ID] = " & lngShow_ID & " And [Visitor ID] = " & ![Visitor ID]
ElseIf ![Visitor Type] = igcExhibitor And rstSettings![Exhibitor Letter] = -1 Then
DoCmd.OpenReport "Rpt_" & Show_Name() & " Exhibitor Letter", acViewNormal, , "[Show ID] = " & lngShow_ID & " And [Visitor ID] = " & ![Visitor ID]
End If
End If
Go_Print_Badges acViewNormal, "[Show ID] = " & lngShow_ID & " And [Visitor ID] = " & ![Visitor ID], "SINGLE", REGISTRATION_BADGE_SIZE
End If
Using the breakpoints I have found it happens at this point:
Code:
Go_Print_Badges acViewNormal, "[Show ID] = " & lngShow_ID & " And [Visitor ID] = " & ![Visitor ID], "SINGLE", REGISTRATION_BADGE_SIZE
Can anyone help?