combo box in form based on table

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a ProjectEntryForm for entering new projects. One of the fields is
CustomerName, which is a drop down combo box based on records in the
CustomerTable, so the user can select an existing customer. If it is not in
the list, I have a "New Customer" button that opens up a form where you can
enter the cutomer name, address, etc. That form then gets closed when all
info is complete. If you then click on the CustomerName drop down, the new
customer still does not appear in the list. If you close and reopen the
ProjectEntryForm, then the new customer appears as part of that drop down.
How can I get the new customer to appear without closing and reopening the
ProjectEntryForm.
Any suggestions are appreciated!
 
Kevin,
You need to 'requery' your combo box to repopulate it with the new data.
You could do this in the OnClose event of your customer form:

Forms!YourMainForm!YourComboBox.Requery

This method assumes the Main form is open.

Although I haven't tested it, I think you could also do this in the
OnActivate event of the Main Form:

Me.YourComboBox.Requery

Good luck!
 
I'm now getting an error message as follows:
Microsoft Access can't find the macro 'Forms!EstimatingPlanEntry!GCName.'
The macro(or its macro group)doesn't exist, or the macro is new but hasn't
been saved. Note that when you enter the macrogroupname.macroname in an
argument, you must specify the name of the macro's macro group was last saved
under.

The form where the combo box exists is EstimatingPlanEntry.
The combo box name is GCName.

I also tried the expression with the Customer form in lieu of
EstimatingPlanEntry, but it netted the same error message. Any further help
is greatly appreciated! Thanks!
Kevin
 
Just to be sure that I understand. You are pressing a button on the
'EstimatingPlanEntry' form to open the 'Customer' form so that you can add
new customers. Are you closing the 'EstimatingPlanEntry' form when you open
the 'Customer' form? The 'EstimatingPlanEntry' form must remain open for the
code to work. Did you add the following to the 'On Close' event of
'Customer' form?

Forms!EstimatingPlanEntry!GCName.Requery

It should work, as long as the 'EstimatingPlanEntry' form is open when the
'Customer' form's On Close event is triggered.

You could also try putting the following in the 'EstimatingPlanEntry' form's
'On Activate' event:
Me.GCName.Requery

In this method, the combo box should be requeried everytime that the
'EstimatingPlanEntry' form first gets the focus.

Is the combo box control's Name the same as the field it is bound to? If it
is different, make sure that you are referencing the controls name, not the
field name.
In your example, I have assumed that the controls name is GCName even if the
underlying field name is different.
 
Dan,
Your are understanding everything correctly, and I am keeping the
'EstimatingPlanEntry' form open as the 'Customer' form is opened and closed.

Maybe this is causing my problem?: The field name is GCName. When I pulled
in that field, it names the control GCName. It doesn't seem that I can
rename the control since it is bound. Do you think that is causing my error?
If so, how do I rename the control?

Also, I tried entering that expression in the On Activate event of the
'EstimatingPlanEntry' form, and I get an error regarding the "Me macro",
which also makes me think it has something to do with the "GCName".

Thanks again!
Kevin
 
Access will automatically give a control the same name as the field it is
bound to. I normally leave it that way to avoid confusion. I don't think
that is the problem. I am wondering if there is a problem with your
"References".

While in the code window, go to 'Tools|References...' In the References
window, there should be a reference to: , 'Visual Basic For Applications',
'Microsoft Access 10.0 Object Library', 'OLE Automation', 'Microsoft DAO 3.6
Object Library' and 'Microsoft ActiveX Data Objects 2.1 Library'. If any of
these are not checked, you must put a check mark next to it to add it. (Your
version numbers might be different depending on the version of Access you are
using. The ones above are for Access XP 2001) Make sure that 'Microsoft DAO
3.6 Object Library' is above 'Microsoft ActiveX Data Objects 2.1 Library' in
the list. Beginning with Access XP, the Microsoft installation defaults to
the ActiveX Object model rather than the DAO object model. Therefore, you
need to manually move the DAO object reference above the ActiveX one. The two
object models can co-exist, but Access will read the first one it encounters
unless you explicitly add DAO or ADO prefixes in the code. There are
priority buttons in the References window to move priorities. Mine are in
the order I listed above.

Post back if this is the problem. I have numerous databases that I do the
exact same thing that you are trying to do. This method works flawlessly in
everyone of them, which leads me to believe that you have a configuration
problem.
 
Back
Top