Hello,
I have the below required fields code that I am using to ensure all required fields are filled before adding a record to our table. However, it is still adding the record even if I leave some of the required fields as blank.
I also tried it with the second code I have below, but it is still adding the record to the table.
I originally had the Required option set to YES in the table, but I removed it thinking that it should still work with these codes. Do I still need to mark these fields as YES in the required section of the table design view?
Also, I have required fields that are either text boxes, combo boxes, and 1 hyperlink text box. Is this causing an issue in either of the codes above?
Thank you
I have the below required fields code that I am using to ensure all required fields are filled before adding a record to our table. However, it is still adding the record even if I leave some of the required fields as blank.
Code:
Dim msg As String, Style As Integer, Title As String
Dim nl As String, ctl As Control
nl = vbNewLine & vbNewLine
For Each ctl In Me.Controls
If ctl.ControlType = acTextBox Then
If ctl.Tag = "*" And Trim(ctl & "") = "" Then
msg = "Data Required for '" & ctl.Name & "' field!" & nl & _
"You can't save this record until this data is provided!" & nl & _
"Enter the data and try again . . . "
Style = vbCritical + vbOKOnly
Title = "Required Data..."
MsgBox msg, Style, Title
ctl.SetFocus
Cancel = True
Exit For
End If
End If
Next
I also tried it with the second code I have below, but it is still adding the record to the table.
Code:
If IsNull(Me.CycleMonth) Then
Cancel = True
Call MsgBox("Cycle Month is Required. Please select Cycle Month.", vbExclamation, "EntryRequired!")
Me.CycleMonth.SetFocus
Exit Sub
End If
If IsNull(Me.DateReviewed) Then
Cancel = True
Call MsgBox("Date Reviewed is Required. Please enter/select Reviewed Date.", vbExclamation, "EntryRequired!")
Me.DateReviewed.SetFocus
Exit Sub
End If
If IsNull(Me.ReportType) Then
Cancel = True
Call MsgBox("Report Type is Required. Please select Report Type.", vbExclamation, "EntryRequired!")
Me.ReportType.SetFocus
Exit Sub
End If
If IsNull(Me.MainSection) Then
Cancel = True
Call MsgBox("Main Section is Required. Please select Main Section.", vbExclamation, "EntryRequired!")
Me.MainSection.SetFocus
Exit Sub
End If
If IsNull(Me.TopicSection) Then
Cancel = True
Call MsgBox("Topic Section is Required. Please select Topic Section.", vbExclamation, "EntryRequired!")
Me.TopicSection.SetFocus
Exit Sub
End If
If IsNull(Me.ReviewerType) Then
Cancel = True
Call MsgBox("Reviewer Type is Required. Please select Reviewer Type.", vbExclamation, "EntryRequired!")
Me.ReviewerType.SetFocus
Exit Sub
End If
If IsNull(Me.Reviewer) Then
Cancel = True
Call MsgBox("Reviewer is Required. Please select Reviewer.", vbExclamation, "EntryRequired!")
Me.Reviewer.SetFocus
Exit Sub
End If
If IsNull(Me.ReviewerReportArea) Then
Cancel = True
Call MsgBox("Reviewer Report Area is Required. Please select Reviewer Report Area.", vbExclamation, "EntryRequired!")
Me.ReviewerReportArea.SetFocus
Exit Sub
End If
If IsNull(Me.Individual) Then
Cancel = True
Call MsgBox("Ownership Individual is Required. Please select Ownership Individual.", vbExclamation, "EntryRequired!")
Me.Individual.SetFocus
Exit Sub
End If
If IsNull(Me.Count) Then
Cancel = True
Call MsgBox("Count is Required. Please enter a Count.", vbExclamation, "EntryRequired!")
'Me.Count.SetFocus
End If
If IsNull(Me.L1) Then
Cancel = True
Call MsgBox("QA Category L1 is Required. Please select QA Category L1.", vbExclamation, "EntryRequired!")
Me.L1.SetFocus
Exit Sub
End If
If IsNull(Me.L2) Then
Cancel = True
Call MsgBox("QA Category L2 is Required. Please select QA Category L2.", vbExclamation, "EntryRequired!")
Me.L2.SetFocus
Exit Sub
End If
If IsNull(Me.L3) Then
Cancel = True
Call MsgBox("QA Category L3 is Required. Please select QA Category L3.", vbExclamation, "EntryRequired!")
Me.L3.SetFocus
Exit Sub
End If
If IsNull(Me.txtHyperlink) Then
Cancel = True
Call MsgBox("PDF File path (Hyperlink) is Required. Please insert PDF File path (Hyperlink).", vbExclamation, "EntryRequired!")
Me.txtHyperlink.SetFocus
Exit Sub
End If
I originally had the Required option set to YES in the table, but I removed it thinking that it should still work with these codes. Do I still need to mark these fields as YES in the required section of the table design view?
Also, I have required fields that are either text boxes, combo boxes, and 1 hyperlink text box. Is this causing an issue in either of the codes above?
Thank you