I have been working on a form and would like it to throw a message if certain fields are not filled in correctly. I have it coded to where it works the way I want it but the issue is I have it in the before update sub and then the button I click to save is coded DoCmd.GoToRecord , , acNewRec.
When I click the save button it runs the before update that highlights the blank fields needed before it can save but then it attempts to save it after and throws an error saying Run time error 2105 You cant go to the specific field. I guess I need to figure out how to stop it from attempting to save after it is determined that certain fields are blank.
When I click the save button it runs the before update that highlights the blank fields needed before it can save but then it attempts to save it after and throws an error saying Run time error 2105 You cant go to the specific field. I guess I need to figure out how to stop it from attempting to save after it is determined that certain fields are blank.
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim strMsg As String
Dim iResponse As Integer
On Error Resume Next
Dim ctl As Control
For Each ctl In Me.Controls
With ctl
If .Tag = "required" Then
If Nz(.Value, "") = "" Then
.BackColor = RGB(255, 255, 191)
If Not Cancel Then .SetFocus
Cancel = True
End If
End If
End With
Next ctl
If Cancel Then MsgBox "Your changes cannot be saved until the fields highlighted have been filled in.", vbCritical, "Missing Data!"
End Sub
Private Sub SaveBtn_Click()
DoCmd.GoToRecord , , acNewRec
End Sub