Event Proceedure Help..

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
 
In form design view, select the 2nd Listbox. Change the tab in the properties window to Event. click in "On Not in List", then click on the 3 dot button.

Choose code builder and place the code you want to modify where the cursor is.

Hope that makes sense and works
 
Yes, I get that far.
The first box works great it's just that while in the same form I add another list box with a different event proceedure.
I can't seem to tell it there are two different proceedures for the two boxes, they both seem to run on the same code it doesn't know I have two different proceedures.
I think it's because I am not ending the code properly. When I look at other sample databases to compare I see a solid lind after "End Sub", I can't seem to do that.
Sample:

End Sub
______________________________________________________
Kind of like a page break. how do you make that solid line?

Thanks for the help!
 
DanG said:
I can't seem to tell it there are two different proceedures for the two boxes, they both seem to run on the same code it doesn't know I have two different proceedures.
a procedure only applies to one control. a procedure is attached to, essentially, the control's name. in the code window, in the dropdown box at the top left of the code window, select a control's name and you will be taken to the code that is attached to that control, if there is any. if there isn't any code, it will create the first lines and last lines of code for you.


DanG said:
I think it's because I am not ending the code properly. When I look at other sample databases to compare I see a solid lind after "End Sub", I can't seem to do that.
Sample:

End Sub
______________________________________________________
Kind of like a page break. how do you make that solid line?

Thanks for the help!
the solid line is not required. it is put in automatically between procedures. if you only have one procedure, there will be no line.
 
Thanks for setting me straight.
I have learned so much on this board and it only hurts a little.
 
VBA is actually quite simple. There are many tutorial sites, but the best way to learn is to just play with it, look at others' code samples... and then ask questions.

Just remember that forums are geared toward people that have time-sensitive problems, or just problems that they can't easily find the answer to. But please, remember to use the site's search function to look-up your problems first... and then post.

Good luck, and have fun!
-modest
 

Users who are viewing this thread

Back
Top Bottom