VBA Code for Combo Box to Find Record

G

Guest

I can not get the Combo Box Wizard to help me create the code to find a
record on my form. As such, I need to write the code myself...but I could
use some help!

Form Name is TEST
Has fields: SettingValue (text box), Comments (text box), and Event (combo
box).

The records that this form should display are the results of a query named
"ValuesForOneSetting"

When the user selects an event from the Events combo box, I would like the
form to update to show the appropriate SettingValue and Comments for that
event.

Hoping for some help!
-Julie
 
K

Ken Snell [MVP]

The form's recordsource query needs to be this:

SELECT * FROM ValuesForOneSetting
WHERE [Event]=Forms!TEST!Event;

On the AfterUpdate event of the Event combo box, use code similar to this to
requery the form:

Private Sub Event_AfterUpdate()
Me.Requery
End Sub
 
G

Guest

Ken,

Thank you for your help. I was unable to get the Requery to do anything,
but found some other posts that suggest using something like:
Me![textfield1_to_update].value = Me![combobox_name].column(x)

That works to update the fields, but it is actually CHANGING the values
instead of finding the record that I select in the combo box. Is this
happening because of the code I am using?

Do you have any suggestions for how to get the form to navigate to a new
record instead of changing the values of the current one?

Thanks in advance!
-Julie

Ken Snell said:
The form's recordsource query needs to be this:

SELECT * FROM ValuesForOneSetting
WHERE [Event]=Forms!TEST!Event;

On the AfterUpdate event of the Event combo box, use code similar to this to
requery the form:

Private Sub Event_AfterUpdate()
Me.Requery
End Sub


--

Ken Snell
<MS ACCESS MVP>

Julie said:
I can not get the Combo Box Wizard to help me create the code to find a
record on my form. As such, I need to write the code myself...but I could
use some help!

Form Name is TEST
Has fields: SettingValue (text box), Comments (text box), and Event (combo
box).

The records that this form should display are the results of a query named
"ValuesForOneSetting"

When the user selects an event from the Events combo box, I would like the
form to update to show the appropriate SettingValue and Comments for that
event.

Hoping for some help!
-Julie
 
K

Ken Snell [MVP]

Is the combo box "Event" bound to a field? If it is, the value in that field
will be changed whenever you make a change in the combo box. You must use an
unbound combo box in the form's header section for the "find" action.

Did you set the form's RecordSource to the query that I posted?
--

Ken Snell
<MS ACCESS MVP>



Julie said:
Ken,

Thank you for your help. I was unable to get the Requery to do anything,
but found some other posts that suggest using something like:
Me![textfield1_to_update].value = Me![combobox_name].column(x)

That works to update the fields, but it is actually CHANGING the values
instead of finding the record that I select in the combo box. Is this
happening because of the code I am using?

Do you have any suggestions for how to get the form to navigate to a new
record instead of changing the values of the current one?

Thanks in advance!
-Julie

Ken Snell said:
The form's recordsource query needs to be this:

SELECT * FROM ValuesForOneSetting
WHERE [Event]=Forms!TEST!Event;

On the AfterUpdate event of the Event combo box, use code similar to this
to
requery the form:

Private Sub Event_AfterUpdate()
Me.Requery
End Sub


--

Ken Snell
<MS ACCESS MVP>

Julie said:
I can not get the Combo Box Wizard to help me create the code to find a
record on my form. As such, I need to write the code myself...but I
could
use some help!

Form Name is TEST
Has fields: SettingValue (text box), Comments (text box), and Event
(combo
box).

The records that this form should display are the results of a query
named
"ValuesForOneSetting"

When the user selects an event from the Events combo box, I would like
the
form to update to show the appropriate SettingValue and Comments for
that
event.

Hoping for some help!
-Julie
 

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

Top