form question

G

Guest

I have two forms in a database. One is a contact details form (name, address,
phone, email etc.). The other form has a subform with a drop down that allows
you to choose names that have been entered into the contact details form.

I want to be able to enter a name into the contact form, and using a command
button, open the other form, and then choose the person's name from the drop
down in the combo box. Trouble is the record does not write until you close
the form, and the other form can't be open or the name won't be populated in
the drop down list. I tried putting a "save record" on the contact details
form but that didn't do any good. Is there a way to do this?

Thanks,
ds
 
S

Steve Schapel

Debbie,

Regarding "the other form can't be open or the name won't be populated
in the drop down list" is not strictly true. You can use a line of code
like this:
Me.NameOfYourCOmboboxOnOtherForm.Requery
.... to update the "drop-down list". This code could be put, for
example, on the Enter Event of the combobox, or the Activate event of
the other form.

When you say "I tried putting a 'save record' on the contact details
form ", what does this really mean? If you used:
DoCmd.RunCommand acCmdSaveRecord
.... or:
Me.Dirty = False
.... in the code behind the command button's Click event, prior to
opening the other form, I would expect this also to solve the problem -
assuming, that is, that the other form is indeed closed (as opposed to
hidden or minimised) at the time.
 
G

Guest

I mean that I put a command button on the contacts form using the wizard. The
name of the button was save record. That didn't work. I subsequently figured
out that you can use a command button called "refresh." I put the refresh
button (again using the wizard) on the contacts form. I enter a name into the
form. I click the refresh button. This populates the name in a combo box that
is on the contacts form. But if the other form is open while I enter the new
data in the contacts form, even if I click the refresh button on the contacts
form, the name still does not populate in the combo box on the other form.

So let me understand: you are suggesting that I put the following line of
code:

Me.NameOfYourCOmboboxOnOtherForm.Requery

in the activate event property of the other form (which is actually a
subform on a main form)

Or do I put the code in the activate event property of the combo box on the
other form (subform)?

and once that code is in the other form I don't have to do anything else?

Please clarify, I hope this makes my question more clear to you.

Thank you. -ds
 
S

Steve Schapel

Debbie,

Pretty much. But a combobox doesn't have an Activate event, you would
use the Enter event of the combobox. Or the Activate event of the form.
But let's just use the combobox's Enter event, that's easier. And of
course, yoiu substitute the actual name of the combobox for
"NameOfYourCOmboboxOnOtherForm".
 
G

Guest

I tried putting the code in the Enter event property of the combo box on the
other form (which is actually a subform) and it gave me an error message,
something about it could not find a "me" macro. Do I have to build a macro
first and then put the code in? What am I missing?

thx.
ds
 
S

Steve Schapel

Debbie,

Aha! I know what you have done. Sorry, I made an assumption!

In the event property itself, you enter [Event Procedure], and then
click the little ellipsis [...] button to the right, which will open the
Visual Basic Editor window. The cursor will be located by default
between 2 lines of code, and then that's where you enter what I gave
you, like this:

Private Sub YourCombobox_Enter()
Me.YourCombobox.Requery
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top