DanG
Registered User.
- Local time
- Today, 11:13
- Joined
- Nov 4, 2004
- Messages
- 477
I am just now starting to look for other solutions to take place of macros.
So I'm real new to VBA and event preceecures.
Currently I am able to copy code from the internet and paste it into an event proceedure for a list box (NotInList event) and modifie it to work like I want (to my amazement!).
The problem comes up when in the same form I try to use the same code on another list box to do the same thing. In the new box I change the references to the new list box, but it seems both boxes are using the same code I can't seem to say this code is for box1 and this code is for box 2.
They both seem to be using the same code for both.
I think that I am not ending the code properly...
Private Sub ClientID_NotInList(NewData As String, Response As _
Integer)
Dim Result
Dim Msg As String
Dim CR As String
CR = Chr$(13)
' Exit this subroutine if the combo box was cleared.
If NewData = "" Then Exit Sub
' Ask the user if he or she wishes to add the new customer.
Msg = "'" & NewData & "' is not in the list." & CR & CR
Msg = Msg & "Do you want to add it?"
If MsgBox(Msg, vbQuestion + vbYesNo) = vbYes Then
' If the user chose Yes, start the Customers form in data entry
' mode as a dialog form, passing the new company name in
' NewData to the OpenForm method's OpenArgs argument. The
' OpenArgs argument is used in Customer form's Form_Load event
' procedure.
DoCmd.OpenForm "Add Client", , , , acAdd, acDialog, NewData
End If
' Look for the customer the user created in the Customers form.
' Result = DLookup("[ClientID]", "Add Client", _
"[ClientID]='" & NewData & "'")
If IsNull(Result) Then
' If the customer was not created, set the Response argument
' to suppress an error message and undo changes.
Response = acDataErrContinue
' Display a customized message.
MsgBox "Please try again!"
Else
' If the customer was created, set the Response argument to
' indicate that new data is being added.
Response = acDataErrAdded
End If
End Sub
I think I need a solid line under the last "End Sub" to finalize the event but how do I do that. Am I starting from ground zero or what? Ha Ha
So I'm real new to VBA and event preceecures.
Currently I am able to copy code from the internet and paste it into an event proceedure for a list box (NotInList event) and modifie it to work like I want (to my amazement!).
The problem comes up when in the same form I try to use the same code on another list box to do the same thing. In the new box I change the references to the new list box, but it seems both boxes are using the same code I can't seem to say this code is for box1 and this code is for box 2.
They both seem to be using the same code for both.
I think that I am not ending the code properly...
Private Sub ClientID_NotInList(NewData As String, Response As _
Integer)
Dim Result
Dim Msg As String
Dim CR As String
CR = Chr$(13)
' Exit this subroutine if the combo box was cleared.
If NewData = "" Then Exit Sub
' Ask the user if he or she wishes to add the new customer.
Msg = "'" & NewData & "' is not in the list." & CR & CR
Msg = Msg & "Do you want to add it?"
If MsgBox(Msg, vbQuestion + vbYesNo) = vbYes Then
' If the user chose Yes, start the Customers form in data entry
' mode as a dialog form, passing the new company name in
' NewData to the OpenForm method's OpenArgs argument. The
' OpenArgs argument is used in Customer form's Form_Load event
' procedure.
DoCmd.OpenForm "Add Client", , , , acAdd, acDialog, NewData
End If
' Look for the customer the user created in the Customers form.
' Result = DLookup("[ClientID]", "Add Client", _
"[ClientID]='" & NewData & "'")
If IsNull(Result) Then
' If the customer was not created, set the Response argument
' to suppress an error message and undo changes.
Response = acDataErrContinue
' Display a customized message.
MsgBox "Please try again!"
Else
' If the customer was created, set the Response argument to
' indicate that new data is being added.
Response = acDataErrAdded
End If
End Sub
I think I need a solid line under the last "End Sub" to finalize the event but how do I do that. Am I starting from ground zero or what? Ha Ha