Hi
I'm using the code below to check the form for validation once the user moves to another record or the current record has lost focus. This is doing want i want, except for the staff_Name field. When the message box pops up to indicate that you need to enter a field in Staff_Name and you hit ok, it comes up with error. This is the only error in the validation process.
I have highlighted the row of code that highlights yellow with the sad red face. I'm guessing that this line of code gives the focus back to the field that has no data entered. The Staff_Name is a combo box, so i tried to change it to a txt box, this made no difference, so i could iliminate the possiblity of the field being the combo box causing the error.
Can anyone help?
I'm using the code below to check the form for validation once the user moves to another record or the current record has lost focus. This is doing want i want, except for the staff_Name field. When the message box pops up to indicate that you need to enter a field in Staff_Name and you hit ok, it comes up with error. This is the only error in the validation process.
I have highlighted the row of code that highlights yellow with the sad red face. I'm guessing that this line of code gives the focus back to the field that has no data entered. The Staff_Name is a combo box, so i tried to change it to a txt box, this made no difference, so i could iliminate the possiblity of the field being the combo box causing the error.
Can anyone help?
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
If Me.Dirty = True Then
Dim Strg As String
Strg = AreAllFieldsFilled
If Strg <> "" Then
MsgBox "Before this Record can be Saved, Data for Field" & vbCr & _
"'" & Replace(Strg, "_", " ") & "' must be supplied.", vbInformation, _
"Data Required..."
Cancel = True
Me.Control(Strg).SetFocus [COLOR=red][B](this is where the error is occuring)[/B][/COLOR]
Exit Sub
End If
End If
End Sub
Private Sub Close_Form_Click()
On Error GoTo Err_Close_Form_Click
If Me.Dirty = True Then
If MsgBox("You have supplied or modified Data within this Record." & vbCr & _
"Do you want to Save this Record?", vbExclamation + vbYesNo, _
"Save Record?") <> vbYes Then
Me.Undo
Else
Dim Strg As String
Strg = AreAllFieldsFilled
If Strg <> "" Then
MsgBox "Before this Record can be Saved, Data for Field" & vbCr & _
"'" & Replace(Strg, "_", " ") & "' must be supplied.", vbInformation, _
"Data Required..."
Me.Controls(Strg).SetFocus
Exit Sub
End If
DoCmd.RunCommand acCmdSaveRecord
End If
Else
Me.Undo
End If
DoCmd.Close acForm, "frmNon_Compliances"
Exit_Close_Form_Click:
Exit Sub
Err_Close_Form_Click:
MsgBox Err.Description
Resume Exit_Close_Form_Click
End Sub
Private Function AreAllFieldsFilled() As String
AreAllFieldsFilled = ""
If IsNull(Me.Work_Order_Number) = True Then AreAllFieldsFilled = "Work_Order_Number"
If IsNull(Me.Staff_Name) = True Then AreAllFieldsFilled = "CIN Raising Officer"
'If IsNull(Me.Staff_Contact) = True Then AreAllFieldsFilled = "Staff_Contact"
If IsNull(Me.Work_Order_Type) = True Then AreAllFieldsFilled = "Work_Order_Type"
If IsNull(Me.Cin_Type) = True Then AreAllFieldsFilled = "CIN_Type"
If IsNull(Me.Inspection_Date) = True Then AreAllFieldsFilled = "Inspection_Date"
If IsNull(Me.CIN_Date) = True Then AreAllFieldsFilled = "CIN_Date"
If IsNull(Me.Response_Due_Date) = True Then AreAllFieldsFilled = "Response_Due_Date"
If IsNull(Me.Issue) = True Then AreAllFieldsFilled = "Issue"
If IsNull(Me.CIN_Status) = True Then AreAllFieldsFilled = "CIN_Status"
Last edited: