On exit, update a search?

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

Guest

I have a form with a command button, which opens a search records form.
Once I get to the record I need, I copy the # and I click QUIT on this
search form and it returns to the previous form. Then I do a find that "#" on
this previous form.
Is there a way to go directly to the record I am looking for from the search
form.
 
Diane,

I'm not an expert on forms development, but I was thinking that you can
dispense with the search records form entirely. Here's something I did the
other day that might be helpful for you, or at least will get you thinking
along the right lines.

I'm assuming that there's room to add a combo box on your main form.

With your main form in design mode, and the wizard option selected on the
toolbox, drag a combo box on to your form. This will bring up the combo box
wizard.

Choose the option to "Find a record on my form based on the value I selected
in my combo box." Choose the field(s) you want to appear in your combo box
(these come from the source for your form - a table or query.) Make sure your
primary key field is one of them. It's up to you whether you want the
primary key field to appear in the combo box list.

When you're done with the wizard, right-click on the combo box on your form
to bring up the properties dialog box. Click the All tab and note the name
of your combo box (something like "Combo25".) Note down this name for later
use.

Switch from Design view to Form view. Test the combo box by selecting a
record and see if the form is updated to display the information for that
record.

Assuming that the combo box works, there is still one thing that needs to be
fixed. If you use the navigation button on your form to move through records,
the combo box won't update to the new record.

To fix this, get back in design view, right-click on the form selector box
(the tiny square at the upper left of the form), then select Properties.
Click the Event tab on the properties dialog and click the On Current event,
then click the Build button (...), then choose Code Builder and click OK.

This brings you into a statement called Private Sub Form_Current, with the
insertion point on a blank line. Type a statement that looks something like
this:

Combo25 = RecordID

In place of Combo25, put the name of your combo box that you noted down
earlier.
In place of RecordID, put the field name of the primary key field on your
form.

The entire event procedure will now look something like this:

Private Sub Form_Current()
Combo25 = RecordID
End Sub

Click the save button on the Visual Basic toolbar. Close the VBA window.

Get back into Form view and test the form by using the navigation button to
switch between records. The field(s) in the combo box should now match those
on the form.

If you have a huge number of records to search through, this combo box
method may be unwieldy. If so, you may want to look at some sample databases
that use a separate search dialog box to give more advanced search
capability, and then copy their method.

Hope this will be of some help.
 
Thanks for the help, but if you say it might be too cumbersome for a huge
database, I won't use it as this gets quite large.
 
Hi Ed

Amazing the little bits you learn on newsgroups. Combo25 = RecordID

Thanks I can see a lot of effort in what you wrote
 
Back
Top