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
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
Private Sub Create_Flag()
On Error GoTo Flag_ERR
With rstFlags
.AddNew
![Show ID] = lngShow_ID
![Visitor ID] = Forms!Frm_Input![Visitor ID]
![Created] = Now()
![First Day On Site] = IIf(boOnSite, Date, Null)
![Computer Name] = GetMachineName()
![Domain Name] = Environ("USERDOMAIN")
![Operator Name] = GetCurrentUser()
![Batch ID] = 0
End With
Exit Sub
Flag_ERR:
MsgBox Err & " : " & Err.Description, vbCritical, "Error in Sub Create_Flag"
End Sub