Ok,
I posted yesterday about having problems with code in a form
Here is what I've come up with do far:
Private Sub Customer__Name_LostFocus()
Dim vTruncate
vTruncate = 4
Forms!Customers![Customer ID] = Left(Customer__Name, vTruncate)
End Sub
Private Sub Customer_ID_NotInList(NewData As String, Response As Integer)
Dim ctl As Control
Set ctl = Me.Customer_ID
' Prompt user to verify they wish to add new value.
If MsgBox("Do you want to add this customer to the table?", vbOKCancel) = vbOK Then
' Set Response argument to indicate that data
' is being added.
Response = acDataErrAdded
' Open dialog box for user to enter data and set new data as default value
DoCmd.OpenForm "Customers", , , , , acDialog
Forms!Customers![Customer ID] = NewData
'requery control to update list addition
Forms!Customers![Customer ID].Requery
Response = acDataErrContinue
Else
' If user chooses Cancel, suppress error message
' and undo changes.
Response = acDataErrContinue
ctl.Undo
End If
End Sub
When I enter a new customer, the customer ID truncates fine. Problem is, what happens if there is already an ID in the table? I just get a generic, duplicate value error. I need to somehow be able to let the client verify that this is, indeed a new customer, and maybe add a number to the end of the Customer ID. The "On NotInList" code should then somehow run and prompt the user to enter the ID somehow... Can anyone help me? I AM trying here... : )
I posted yesterday about having problems with code in a form
Here is what I've come up with do far:
Private Sub Customer__Name_LostFocus()
Dim vTruncate
vTruncate = 4
Forms!Customers![Customer ID] = Left(Customer__Name, vTruncate)
End Sub
Private Sub Customer_ID_NotInList(NewData As String, Response As Integer)
Dim ctl As Control
Set ctl = Me.Customer_ID
' Prompt user to verify they wish to add new value.
If MsgBox("Do you want to add this customer to the table?", vbOKCancel) = vbOK Then
' Set Response argument to indicate that data
' is being added.
Response = acDataErrAdded
' Open dialog box for user to enter data and set new data as default value
DoCmd.OpenForm "Customers", , , , , acDialog
Forms!Customers![Customer ID] = NewData
'requery control to update list addition
Forms!Customers![Customer ID].Requery
Response = acDataErrContinue
Else
' If user chooses Cancel, suppress error message
' and undo changes.
Response = acDataErrContinue
ctl.Undo
End If
End Sub
When I enter a new customer, the customer ID truncates fine. Problem is, what happens if there is already an ID in the table? I just get a generic, duplicate value error. I need to somehow be able to let the client verify that this is, indeed a new customer, and maybe add a number to the end of the Customer ID. The "On NotInList" code should then somehow run and prompt the user to enter the ID somehow... Can anyone help me? I AM trying here... : )