I have a form for entering employee contributions (frmContributions) that contains an unbound combo box to search for employee names (from tblContributors). If the user enters a name that is not already part of the list, I want to give the option of adding a new employee directly on this form. Current code:
Private Sub cmbFindEmployee_NotInList(NewData As String, Response As Integer)
'Ask the user if they want to add a new Employee
Dim strMessage As String
strMessage = "Do you want to add a new Employee?"
If Confirm(strMessage) Then
'Act like the New Employee button was clicked; open a blank record for user to enter new employee
DoCmd.GoToRecord acDataForm, "frmContributions", acNewRec
Else
Response = acDataErrDisplay 'Display the error
End If
End Sub
The Confirm function code is:
Public Function Confirm(strMessage As String) As Boolean
'Ask the user to confirm an action, returning True or False
Dim bytChoice As Byte
bytChoice = MsgBox(strMessage, vbQuestion + vbOKCancel, conAppName)
If bytChoice = vbOK Then
Confirm = True
Else
Confirm = False
End If
End Function
The code brings up the Confirm msgbox with the appropriate question, but gets into a loop when the user clicks OK then gets Run-Time error 2105 when user clicks Cancel with the message "You can't go to the specified record"
Any assistance or a point in the right direction is appreciated!
Private Sub cmbFindEmployee_NotInList(NewData As String, Response As Integer)
'Ask the user if they want to add a new Employee
Dim strMessage As String
strMessage = "Do you want to add a new Employee?"
If Confirm(strMessage) Then
'Act like the New Employee button was clicked; open a blank record for user to enter new employee
DoCmd.GoToRecord acDataForm, "frmContributions", acNewRec
Else
Response = acDataErrDisplay 'Display the error
End If
End Sub
The Confirm function code is:
Public Function Confirm(strMessage As String) As Boolean
'Ask the user to confirm an action, returning True or False
Dim bytChoice As Byte
bytChoice = MsgBox(strMessage, vbQuestion + vbOKCancel, conAppName)
If bytChoice = vbOK Then
Confirm = True
Else
Confirm = False
End If
End Function
The code brings up the Confirm msgbox with the appropriate question, but gets into a loop when the user clicks OK then gets Run-Time error 2105 when user clicks Cancel with the message "You can't go to the specified record"
Any assistance or a point in the right direction is appreciated!