Hi Steph,
With the form open in design view, click on View > Code. This should open a
code module associated with the form (also known as CBF or code behind form).
Paste the code I gave you into the new code module. Then click on Debug >
Compile ProjectName, where ProjectName represents the name of your VBA
project (likely the name of your database, but one can change it).
Note: It is a good habit to get into to click on Debug > Compile
periodically, when you are working with VBA code. That way, you can correct
compile errors as they happen, instead of letting lots of them build up.
Close, or minimize, the code module. Back in form design view, display the
Properties dialog, if it is not already displayed, by clicking on View >
Properties (or pressing the F4 button [Access 2002 and later]). Select the
combo box in question. You should see the name of the combo box in the blue
title bar of the Properties dialog. Click on the Event tab of this dialog.
You should now see [Event Procedure] listed for the After Update listing, if
all worked okay.
As an alternative to simply clicking on View > Code at the beginning, you
could have clicked into the After Update event procedure for the combo box.
You should now see a small button with three dots appear. Click on this build
button. One of two things will happen, depending on a setting that you have
under Tools > Options on the Forms/Reports tab. You will either jump directly
into the code module [ie. "Always Use Event Procedures" is checked as your
option], with the skelton of the new event procedure already created, ie.:
Option Compare Database
Option Explicit
Private Sub Aid_AfterUpdate()
End Sub
or, you will see a "Choose Builder" dialog (default setting, with "Always
Use Event Procedures" unchecked) where you need to pick from a list that
reads:
Expression Builder
Macro Builder
Code Builder
In this case, you want to click on Code Builder.
Try out the various methods I have outlined to open the code behind form,
with and without the "Always Use Event Procedures" checked. Don't add
duplicate copies of the same named event procedure, or else you will generate
a compile error.
MOST IMPORTANTLY: When you first create a new module, make sure that you see
Option Explicit as the second line of code, automatically inserted for you.
If you do not see this, then you should set the VBA option "Require Variable
Declaration". I talk about that more in this short "Gem Tip":
Always Use Option Explicit
http://www.access.qbuilt.com/html/gem_tips.html#VBEOptions
A couple more points:
Back on the Properties dialog, with the properties displayed for the Form
(you should see the word "Form" in the blue title bar), if you click on the
Other tab, you should see a property labelled "Has Module". If this is
already Yes, then you have an existing code module associated with this form.
If it is No (ie. a brand new form, or a form that has no code module), then
you should notice that this property is automatically changed to Yes, as soon
as you do anything that causes the creation of a new form module, such as
clicking on View > Code, or following the Build button and selecting Event
Procedure if you see the Choose Builder dialog.
Sometimes, it is possible for a control to become "disassociated" with an
Event Procedure. In other words, you might have the procedure pasted into the
form's code module, but you do not see [Event Procedure] when you examine the
Event tab for the control in question. This can easily happen if you cut the
control from one section of a form, and paste it into a different section. In
that case, the event in question will seem "dead". Nothing happens when you
know that something should happen, for example nothing happens when you click
on a command button, if it has lost it's On Click event procedure. The fix is
usually pretty easy: Just select Event procedure from the dropdown, and then
click on the Build Button. You will usually always "re-find" the event
procedure, unless, of course the control was renamed, in which case a new
event procedure will be created.
I hope this helps!
Tom Wickerath
Microsoft Access MVP
http://www.access.qbuilt.com/html/expert_contributors.html
http://www.access.qbuilt.com/html/search.html
__________________________________________
Scuda said:
Thanks Tom! Now a stupid question, where again do I paste that code, was it
on the Row Source?
Thanks again for all the help!