Hello!
Currently have a database setup to enter information from drivers. The SOCIAL field cannot be left blank, and I would like it to say a message "Please add drivers social!" And cancel the process.
As of right now, when adding and or updating an existing record, without a social, the error code 3144 comes up. How do I go about setting up the message and getting rid of the error?
Code Below;
Private Sub cmdAdd_Click()
'when we click on button Add there are two options
'1. for insert
'2. for update
If Me.txtSocial.Tag & "" = "" Then
' this is for insert new
'add data to table
CurrentDb.Execute "INSERT INTO tblDrivers(tbLast, tbFirst, tbDOB, tbCDL, tbCDLEXP, tbCDLST, tbMC, tbMCEXP, tbCOM, tbHire, tbSocial, tbDrug) " & _
" VALUES('" & Me.txtLast & "', '" & Me.txtFirst & "', '" & Me.txtDOB & "', '" & Me.txtCDL & "', '" & Me.txtCDLEXP & "', '" & Me.txtCDLST & "', '" & _
Me.txtMC & "', '" & Me.txtMCEXP & "', '" & Me.txtCMP & "', '" & Me.txtHIRE & "', '" & Me.txtSocial & "', '" & Me.txtDrug & "', '" & Me.txtPhone & "')"
Else
'otherwise (Tag of txtSocial store to the Social of Drivers to be notified)
CurrentDb.Execute "UPDATE tblDrivers " & _
" SET tbSocial=" & Me.txtSocial & _
", tbfirst='" & Me.txtFirst & "'" & _
", tblast='" & Me.txtLast & "'" & _
", tbDOB='" & Me.txtDOB & "'" & _
", tbCDL='" & Me.txtCDL & "'" & _
", tbCDLEXP='" & Me.txtCDLEXP & "'" & _
", tbMC='" & Me.txtMC & "'" & _
", tbMCEXP='" & Me.txtMCEXP & "'" & _
", tbCOM='" & Me.txtCMP & "'" & _
", tbHire='" & Me.txtHIRE & "'" & _
", tbDrug='" & Me.txtDrug & "'" & _
", tbPhone='" & Me.txtPhone & "'" & _
" WHERE tbSocial=" & Me.txtSocial.Tag
End If
'clear form
cmdClear_Click
'refresh data in list on form
frmDriverSub.Form.Requery
End Sub
Private Sub cmdClear_Click()
Me.txtLast = ""
Me.txtFirst = ""
Me.txtDOB = ""
Me.txtCDL = ""
Me.txtCDLEXP = ""
Me.txtCDLST = ""
Me.txtMC = ""
Me.txtMCEXP = ""
Me.txtCMP = ""
Me.txtHIRE = ""
Me.txtSocial = ""
Me.txtDrug = ""
Me.txtPhone = ""
'focus on ID text Box
Me.txtSocial.SetFocus
'set button edit to enable
Me.cmdEdit.Enabled = True
'change caption of buton add to Add
Me.cmdAdd.Caption = "Add"
'clear tag on txtSocial for reset new
Me.txtSocial.Tag = ""
End Sub
Private Sub cmdClose_Click()
DoCmd.Close
End Sub
Private Sub cmdEdit_Click()
'check whether data exists in list
If Not (Me.frmDriverSub.Form.Recordset.EOF And Me.frmDriverSub.Form.Recordset.BOF) Then
'get data to text box control
With Me.frmDriverSub.Form.Recordset
Me.txtSocial = .Fields("tbSocial")
Me.txtLast = .Fields("tbLast")
Me.txtFirst = .Fields("tbFirst")
Me.txtDOB = .Fields("tbDOB")
Me.txtCDL = .Fields("tbCDL")
Me.txtCDLEXP = .Fields("tbCDLEXP")
Me.txtCDLST = .Fields("tbCDLST")
Me.txtMC = .Fields("tbMC")
Me.txtMCEXP = .Fields("tbMCEXP")
Me.txtCMP = .Fields("tbCOM")
Me.txtHIRE = .Fields("tbHIRE")
Me.txtSocial = .Fields("tbSOCIAL")
Me.txtDrug = .Fields("tbDRUG")
Me.txtPhone = .Fields("tbPhone")
'store social of student in Tag of txtSocial in case Social is modified
Me.txtSocial.Tag = .Fields("tbSocial")
'change caption of button add to Update
Me.cmdAdd.Caption = "Update"
'disable buton edit
Me.cmdEdit.Enabled = False
'refresh data in list on form
frmDriverSub.Form.Requery
End With
End If
End Sub
Private Sub Command40_Click()
End Sub