M
Mikev
Here is the code behind the save button and relavant
validation code as well as save entry procedure.
Good luck and TIA
Private Sub cmdSave_Click()
On Error GoTo HandleError
Dim blnValidEntry As Boolean
'Validate the Entry
blnValidEntry = ValidateEntry()
If blnValidEntry Then
SaveEntry
DoCmd.Close acForm, mTHISFORMNAME
End If
Done:
Exit Sub
HandleError:
DisplayError Err
Resume Done
End Sub
Private Function ValidateEntry() As Boolean
On Error GoTo HandleError
Dim blnValidPropDetails As Boolean
'Validate Property Details (if required)
mblnCreateRel = False
blnValidPropDetails = True
If Me.txtMapNumber.Visible = True Then
If Nz(Me.opgRelationship, 0) <> 0 And Nz
(Me.opgRelationship, 0) <> 4 Then
mblnCreateRel = True
' If Nz(Me.txtMapNumber, "") = "" Then
' gstrMsg = "You need to enter a Map Number."
' MsgBox gstrMsg, vbExclamation, gAPPNAME
' Me.txtMapNumber.SetFocus
' blnValidPropDetails = False
' ElseIf Nz(Me.txtMapReference, "") = "" Then
' gstrMsg = "You need to enter a Map Number."
' MsgBox gstrMsg, vbExclamation, gAPPNAME
' Me.txtMapReference.SetFocus
' blnValidPropDetails = False
' End If
End If
End If
'Were Property Details Valid
If blnValidPropDetails = False Then
ValidateEntry = False
'Validate Surname
ElseIf Nz(Me.txtSurname, "") = "" Then
gstrMsg = "You need to enter a surname."
MsgBox gstrMsg, vbExclamation, gAPPNAME
Me.txtSurname.SetFocus
ValidateEntry = False
'Validate StreetName
ElseIf Nz(Me.cboStreetName, "") = "" Then
gstrMsg = "You need to enter a street name."
MsgBox gstrMsg, vbExclamation, gAPPNAME
Me.cboStreetName.SetFocus
ValidateEntry = False
'Validate Suburb
ElseIf Nz(Me.cboSuburb, "") = "" Then
gstrMsg = "You need to enter a suburb."
MsgBox gstrMsg, vbExclamation, gAPPNAME
Me.cboSuburb.SetFocus
ValidateEntry = False
Else
ValidateEntry = True
End If
Done:
Exit Function
HandleError:
DisplayError Err
ValidateEntry = False
Resume Done
End Function
Public Sub SaveEntry()
On Error GoTo HandleError
Dim objProperty As clsProperty
Dim objPropertyRel As clsPropertyRelationship
Dim strUpdateType As String
Dim intKey As Integer
'Set the fields
mobjClient.Title = Nz(Me.cboTitle, "")
mobjClient.GivenName = Nz(Me.txtFirstName, "")
mobjClient.Surname = Nz(Me.txtSurname, "")
mobjClient.NameSuffix = Nz(Me.cboNameSuffix, "")
mobjClient.Salutation = Nz(Me.txtSalutation, "")
mobjClient.UnitNumber = Nz(Me.txtUnitNumber, "")
mobjClient.StreetNumber = Nz(Me.txtStreetNumber, "")
mobjClient.StreetName = Nz(Me.cboStreetName, "")
mobjClient.StreetType = Nz(Me.cboStreetType, "")
mobjClient.Suburb = Nz(Me.cboSuburb, "")
mobjClient.State = Nz(Me.cboState, "")
mobjClient.Postcode = Nz(Me.txtPostcode, "")
mobjClient.PhoneStdBH = Nz(Me.txtPhoneStdBH, "")
mobjClient.PhoneBH = Nz(Me.txtPhoneBH, "")
mobjClient.PhoneStdAH = Nz(Me.txtPhoneStdAH, "")
mobjClient.PhoneAH = Nz(Me.txtPhoneAH, "")
mobjClient.PhoneMobile = Nz(Me.txtPhoneMobile, "")
mobjClient.Email = Nz(Me.txtEmail, "")
mobjClient.FaxStd = Nz(Me.txtFaxStd, "")
mobjClient.Fax = Nz(Me.txtFax, "")
mobjClient.PermissionToEmail = Nz
(Me.chkPermissionToEmail, 0)
mobjClient.PermissionToSMS = Nz
(Me.chkPermissionToSMS, 0)
mobjClient.DateOfBirth = Nz(Me.txtDOB, 0)
mobjClient.Occupation = Nz(Me.txtOccupation, "")
mobjClient.BusinessName = Nz(Me.txtBusinessName, "")
mobjClient.BusinessUnitNumber = Nz
(Me.txtBusinessUnitNumber, "")
mobjClient.BusinessStreetNumber = Nz
(Me.txtBusinessStreetNumber, "")
mobjClient.BusinessStreetName = Nz
(Me.cboBusinessStreetName, "")
mobjClient.BusinessStreetType = Nz
(Me.cboBusinessStreetType, "")
mobjClient.BusinessSuburb = Nz
(Me.cboBusinessSuburb, "")
mobjClient.BusinessState = Nz
(Me.cboBusinessState, "")
mobjClient.BusinessPostcode = Nz
(Me.txtBusinessPostcode, "")
mobjClient.BusinessCountry = Nz
(Me.cboBusinessCountry, "")
mobjClient.BusinessPhoneStd = Nz
(Me.txtBusinessPhoneStd, "")
mobjClient.BusinessPhone = Nz
(Me.txtBusinessPhone, "")
mobjClient.BusinessFaxStd = Nz
(Me.txtBusinessFaxStd, "")
mobjClient.BusinessFax = Nz(Me.txtBusinessFax, "")
mobjClient.PAName = Nz(Me.txtPAName, "")
mobjClient.Notes = Nz(Me.txtNotes, "")
'Either update the exisitng record or create a new one
If mstrRecType = "E" Then
strUpdateType = "UPDATE"
mobjClient.UpdateEntry
Else
strUpdateType = "CREATE"
intKey = mobjClient.NextKey
If intKey = -1 Then
mstrGotoForm = mCLIENTSEARCHFORM
mstrOpenArgs = mstrSearchFormUse
Err.Raise 513, Me.Name & ":" &
Me.ActiveControl.Name, "Unable to get " & mKEYNAME & ". "
& mRECORDNAME & " was not created. Please contact your
System Administrator."
Else
mobjClient.ClientId = intKey
mintClientId = intKey
If mstrSearchFormUse = mCLIENTSEARCH Then
mstrGotoForm = mCLIENTVIEWFORM
mstrOpenArgs = mintClientId
End If
End If
mobjClient.CreateEntry
'Copy the temp Checklist to the actual checklist table
mobjChecklist.RecordId = mintClientId
mobjChecklist.LoadIntoActual
'Create the relationship if need be
If mblnCreateRel = True Then
'Check if the property already exists
Set objProperty = New clsProperty
objProperty.StreetName = Nz(Me.cboStreetName, "")
objProperty.StreetNumber = Nz(Me.txtStreetNumber, "")
objProperty.UnitNumber = Nz(Me.txtUnitNumber, "")
objProperty.Postcode = Nz(Me.txtPostcode, "")
If objProperty.CheckDuplicateProperty = True Then
mintPropertyId = objProperty.PropertyId
Else
'It does not - so create it
mintPropertyId = objProperty.NextKey
objProperty.PropertyId = mintPropertyId
objProperty.StreetType = Nz(Me.cboStreetType, "")
objProperty.Suburb = Nz(Me.cboSuburb, "")
objProperty.State = Nz(Me.cboState, "")
objProperty.Country = Nz(Me.cboCountry, "")
objProperty.YearBuilt = Nz(Me.txtYearBuilt, "")
objProperty.MapNumber = Nz(Me.txtMapNumber, "")
objProperty.MapReference = Nz
(Me.txtMapReference, "")
objProperty.CreateEntry
End If
Set objProperty = Nothing
'Create the relationship
Set objPropertyRel = New clsPropertyRelationship
objPropertyRel.PropertyRelId = objPropertyRel.NextKey
objPropertyRel.ActiveStatus = "A"
objPropertyRel.DateRelationshipStart = Now()
Select Case Me.opgRelationship
Case 1
objPropertyRel.PropertyRelationshipTypeId =
gOWNER
Case 2
objPropertyRel.PropertyRelationshipTypeId =
gLANDLORD
Case 3
objPropertyRel.PropertyRelationshipTypeId =
gTENANT
End Select
objPropertyRel.PropertyStatusId = gNOSTATUS
objPropertyRel.ClientId = mintClientId
objPropertyRel.PropertyId = mintPropertyId
objPropertyRel.StaffId = gintCurrStaffId
objPropertyRel.CreateEntry
Set objPropertyRel = Nothing
End If
End If
'Update the Audit Log
gstrMsg = mRECORDNAME & ": " & mobjClient.ClientId & " -
" & Me.txtFirstName & " " & Me.txtSurname
UpdateAuditLog gstrMsg, strUpdateType
mblnDirty = False
mblnSaved = True
Done:
Exit Sub
HandleError:
DisplayError Err
Resume Done
End Sub
validation code as well as save entry procedure.
Good luck and TIA
Private Sub cmdSave_Click()
On Error GoTo HandleError
Dim blnValidEntry As Boolean
'Validate the Entry
blnValidEntry = ValidateEntry()
If blnValidEntry Then
SaveEntry
DoCmd.Close acForm, mTHISFORMNAME
End If
Done:
Exit Sub
HandleError:
DisplayError Err
Resume Done
End Sub
Private Function ValidateEntry() As Boolean
On Error GoTo HandleError
Dim blnValidPropDetails As Boolean
'Validate Property Details (if required)
mblnCreateRel = False
blnValidPropDetails = True
If Me.txtMapNumber.Visible = True Then
If Nz(Me.opgRelationship, 0) <> 0 And Nz
(Me.opgRelationship, 0) <> 4 Then
mblnCreateRel = True
' If Nz(Me.txtMapNumber, "") = "" Then
' gstrMsg = "You need to enter a Map Number."
' MsgBox gstrMsg, vbExclamation, gAPPNAME
' Me.txtMapNumber.SetFocus
' blnValidPropDetails = False
' ElseIf Nz(Me.txtMapReference, "") = "" Then
' gstrMsg = "You need to enter a Map Number."
' MsgBox gstrMsg, vbExclamation, gAPPNAME
' Me.txtMapReference.SetFocus
' blnValidPropDetails = False
' End If
End If
End If
'Were Property Details Valid
If blnValidPropDetails = False Then
ValidateEntry = False
'Validate Surname
ElseIf Nz(Me.txtSurname, "") = "" Then
gstrMsg = "You need to enter a surname."
MsgBox gstrMsg, vbExclamation, gAPPNAME
Me.txtSurname.SetFocus
ValidateEntry = False
'Validate StreetName
ElseIf Nz(Me.cboStreetName, "") = "" Then
gstrMsg = "You need to enter a street name."
MsgBox gstrMsg, vbExclamation, gAPPNAME
Me.cboStreetName.SetFocus
ValidateEntry = False
'Validate Suburb
ElseIf Nz(Me.cboSuburb, "") = "" Then
gstrMsg = "You need to enter a suburb."
MsgBox gstrMsg, vbExclamation, gAPPNAME
Me.cboSuburb.SetFocus
ValidateEntry = False
Else
ValidateEntry = True
End If
Done:
Exit Function
HandleError:
DisplayError Err
ValidateEntry = False
Resume Done
End Function
Public Sub SaveEntry()
On Error GoTo HandleError
Dim objProperty As clsProperty
Dim objPropertyRel As clsPropertyRelationship
Dim strUpdateType As String
Dim intKey As Integer
'Set the fields
mobjClient.Title = Nz(Me.cboTitle, "")
mobjClient.GivenName = Nz(Me.txtFirstName, "")
mobjClient.Surname = Nz(Me.txtSurname, "")
mobjClient.NameSuffix = Nz(Me.cboNameSuffix, "")
mobjClient.Salutation = Nz(Me.txtSalutation, "")
mobjClient.UnitNumber = Nz(Me.txtUnitNumber, "")
mobjClient.StreetNumber = Nz(Me.txtStreetNumber, "")
mobjClient.StreetName = Nz(Me.cboStreetName, "")
mobjClient.StreetType = Nz(Me.cboStreetType, "")
mobjClient.Suburb = Nz(Me.cboSuburb, "")
mobjClient.State = Nz(Me.cboState, "")
mobjClient.Postcode = Nz(Me.txtPostcode, "")
mobjClient.PhoneStdBH = Nz(Me.txtPhoneStdBH, "")
mobjClient.PhoneBH = Nz(Me.txtPhoneBH, "")
mobjClient.PhoneStdAH = Nz(Me.txtPhoneStdAH, "")
mobjClient.PhoneAH = Nz(Me.txtPhoneAH, "")
mobjClient.PhoneMobile = Nz(Me.txtPhoneMobile, "")
mobjClient.Email = Nz(Me.txtEmail, "")
mobjClient.FaxStd = Nz(Me.txtFaxStd, "")
mobjClient.Fax = Nz(Me.txtFax, "")
mobjClient.PermissionToEmail = Nz
(Me.chkPermissionToEmail, 0)
mobjClient.PermissionToSMS = Nz
(Me.chkPermissionToSMS, 0)
mobjClient.DateOfBirth = Nz(Me.txtDOB, 0)
mobjClient.Occupation = Nz(Me.txtOccupation, "")
mobjClient.BusinessName = Nz(Me.txtBusinessName, "")
mobjClient.BusinessUnitNumber = Nz
(Me.txtBusinessUnitNumber, "")
mobjClient.BusinessStreetNumber = Nz
(Me.txtBusinessStreetNumber, "")
mobjClient.BusinessStreetName = Nz
(Me.cboBusinessStreetName, "")
mobjClient.BusinessStreetType = Nz
(Me.cboBusinessStreetType, "")
mobjClient.BusinessSuburb = Nz
(Me.cboBusinessSuburb, "")
mobjClient.BusinessState = Nz
(Me.cboBusinessState, "")
mobjClient.BusinessPostcode = Nz
(Me.txtBusinessPostcode, "")
mobjClient.BusinessCountry = Nz
(Me.cboBusinessCountry, "")
mobjClient.BusinessPhoneStd = Nz
(Me.txtBusinessPhoneStd, "")
mobjClient.BusinessPhone = Nz
(Me.txtBusinessPhone, "")
mobjClient.BusinessFaxStd = Nz
(Me.txtBusinessFaxStd, "")
mobjClient.BusinessFax = Nz(Me.txtBusinessFax, "")
mobjClient.PAName = Nz(Me.txtPAName, "")
mobjClient.Notes = Nz(Me.txtNotes, "")
'Either update the exisitng record or create a new one
If mstrRecType = "E" Then
strUpdateType = "UPDATE"
mobjClient.UpdateEntry
Else
strUpdateType = "CREATE"
intKey = mobjClient.NextKey
If intKey = -1 Then
mstrGotoForm = mCLIENTSEARCHFORM
mstrOpenArgs = mstrSearchFormUse
Err.Raise 513, Me.Name & ":" &
Me.ActiveControl.Name, "Unable to get " & mKEYNAME & ". "
& mRECORDNAME & " was not created. Please contact your
System Administrator."
Else
mobjClient.ClientId = intKey
mintClientId = intKey
If mstrSearchFormUse = mCLIENTSEARCH Then
mstrGotoForm = mCLIENTVIEWFORM
mstrOpenArgs = mintClientId
End If
End If
mobjClient.CreateEntry
'Copy the temp Checklist to the actual checklist table
mobjChecklist.RecordId = mintClientId
mobjChecklist.LoadIntoActual
'Create the relationship if need be
If mblnCreateRel = True Then
'Check if the property already exists
Set objProperty = New clsProperty
objProperty.StreetName = Nz(Me.cboStreetName, "")
objProperty.StreetNumber = Nz(Me.txtStreetNumber, "")
objProperty.UnitNumber = Nz(Me.txtUnitNumber, "")
objProperty.Postcode = Nz(Me.txtPostcode, "")
If objProperty.CheckDuplicateProperty = True Then
mintPropertyId = objProperty.PropertyId
Else
'It does not - so create it
mintPropertyId = objProperty.NextKey
objProperty.PropertyId = mintPropertyId
objProperty.StreetType = Nz(Me.cboStreetType, "")
objProperty.Suburb = Nz(Me.cboSuburb, "")
objProperty.State = Nz(Me.cboState, "")
objProperty.Country = Nz(Me.cboCountry, "")
objProperty.YearBuilt = Nz(Me.txtYearBuilt, "")
objProperty.MapNumber = Nz(Me.txtMapNumber, "")
objProperty.MapReference = Nz
(Me.txtMapReference, "")
objProperty.CreateEntry
End If
Set objProperty = Nothing
'Create the relationship
Set objPropertyRel = New clsPropertyRelationship
objPropertyRel.PropertyRelId = objPropertyRel.NextKey
objPropertyRel.ActiveStatus = "A"
objPropertyRel.DateRelationshipStart = Now()
Select Case Me.opgRelationship
Case 1
objPropertyRel.PropertyRelationshipTypeId =
gOWNER
Case 2
objPropertyRel.PropertyRelationshipTypeId =
gLANDLORD
Case 3
objPropertyRel.PropertyRelationshipTypeId =
gTENANT
End Select
objPropertyRel.PropertyStatusId = gNOSTATUS
objPropertyRel.ClientId = mintClientId
objPropertyRel.PropertyId = mintPropertyId
objPropertyRel.StaffId = gintCurrStaffId
objPropertyRel.CreateEntry
Set objPropertyRel = Nothing
End If
End If
'Update the Audit Log
gstrMsg = mRECORDNAME & ": " & mobjClient.ClientId & " -
" & Me.txtFirstName & " " & Me.txtSurname
UpdateAuditLog gstrMsg, strUpdateType
mblnDirty = False
mblnSaved = True
Done:
Exit Sub
HandleError:
DisplayError Err
Resume Done
End Sub