Hi,
I am using the following codes to validate all fields on the form are inputed before update:
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim Msg As String, Style As Integer, Title As String
Dim DL As String, ctl As Control
DL = vbNewLine & vbNewLine
For Each ctl In Me.Controls
If ctl.ControlType = acTextBox Then
If Trim(ctl.Value & “”) = “” Then
Msg = “‘” & ctl.Name & “‘ is Required!” & DL & _
“Please enter a value to proceed . . .”
Style = vbInformation + vbOKOnly
Title = “Required Data Missing! . . .”
MsgBox Msg, Style, Title
ctl.SetFocus
Cancel = True
Exit For
End If
End If
Next
End Sub
I have a add button on the form with codes in on click event below:
DoCmd.GoToRecord , , acNewRec
Now if I have some fields are blank and then click the add button, the warning message pops up to to inform user that which field is missing. Then I get a error message: Run-time error ‘2105’. You can’t go to the specified record. If I click “Debug,” and then it open VB window with yellow highlight on DoCmd.GoToRecord , , acNewRec.
Any idea why it happened?
Thanks