Hi, I posted previously that I was having issues getting a form to update a table. Thanks to everyone's help, it's working now. I'm still having one issue though.
The form has required fields and I have a custom message box that pops up when one or more field is left blank. When I click "ok" to the message box, I'm getting: Run-time error '2105': You can't go to the specified record.
When I click "End", it takes me back into the form and I'm able to continue entering the fields and when I click Enter, it is updating the table successfully.
I've attempted to stop error 2105 from appearing, but haven't been successful. Looking for feedback. I'm VERY new to VBA so as much detail as you can provide would be most appreciated!
Here's the code:
The form has required fields and I have a custom message box that pops up when one or more field is left blank. When I click "ok" to the message box, I'm getting: Run-time error '2105': You can't go to the specified record.
When I click "End", it takes me back into the form and I'm able to continue entering the fields and when I click Enter, it is updating the table successfully.
I've attempted to stop error 2105 from appearing, but haven't been successful. Looking for feedback. I'm VERY new to VBA so as much detail as you can provide would be most appreciated!
Here's the code:
Code:
Option Compare Database
Private Sub cboEmpID_Change()
Me.txtLegalName.Value = Me.cboEmpID.Column(1)
Me.txtDOH.Value = Me.cboEmpID.Column(2)
Me.txtLocation.Value = Me.cboEmpID.Column(3)
Me.txtMgr.Value = Me.cboEmpID.Column(4)
Me.txtHRBP.Value = Me.cboEmpID.Column(5)
End Sub
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim sMsg As String
If Nz(Me.txtDateIssued, "") = "" Then
sMsg = "Date Issued " & vbCrLf
End If
If Nz(Me.CAPIPLevel, "") = "" Then
sMsg = sMsg & "CA/PIP Level " & vbCrLf
End If
If Nz(Me.Reason, "") = "" Then
sMsg = sMsg & "Reason " & vbCrLf
End If
If Nz(Me.HRAdvisor, "") = "" Then
sMsg = sMsg & "HR Advisor " & vbCrLf
End If
If sMsg = "" Then Exit Sub
MsgBox "The following fields are missing data; " & vbCrLf & sMsg, vbInformation, "Missing data!"
Cancel = True
End Sub
Private Sub Form_Current()
End Sub
Private Sub Form_Error(DataErr As Integer, Response As Integer)
Select Case DataErr
Case 2105
Response = acDataErrContinue
Case Else
Response = acDataErrDisplay
End Select
End Sub
Private Sub NextRecord_Click()
DoCmd.GoToRecord , , acNewRec
End Sub