Set Combo box's displayed value on form open/load (1 Viewer)

tmyers

Well-known member
Local time
Today, 15:30
Joined
Sep 8, 2020
Messages
1,090
Let me preface this with I dont know if this would be an on load, or on open. My form is already technically "open", but I am doing a docmd.openform to move to a different record.

In the combobox, I have code in an after update even to move to a specific record determined by the value selected in the combo box. The problem is when the form "reopens" or loads to that record (I REALLY don't know which is technically being done), the combo box just defaults to its first value. How can I have it show the value of the record it is actually on?

An an example would be like such:
Combobox with Name1, Name2, Name3 as available selectable options.
You choose Name2 which then moves to the record Name2 but after moving to that record, the combobox just displays Name1 since it is first in the list. I would want it to show Name2.

This is probably another simple option I have missed somewhere within properties.
 

Minty

AWF VIP
Local time
Today, 20:30
Joined
Jul 26, 2013
Messages
10,368
Firstly I suspect the fact you are using the open form method is actually the cause of your problem. if the form is already open you should be able to simply find the relevant record.

Normally an unbound combo won't magically reset to another value - it would / should stay on whatever you set it to unless some code or event is changing it. Hence my guessing it your methodology causing the issue?
 

tmyers

Well-known member
Local time
Today, 15:30
Joined
Sep 8, 2020
Messages
1,090
I will change from openform to gotorecord and see if that remedies the problem.
 

tmyers

Well-known member
Local time
Today, 15:30
Joined
Sep 8, 2020
Messages
1,090
Actually, I have never used gotorecord. I will have to read how to actually write that. I have always used OpenForm.
 

moke123

AWF VIP
Local time
Today, 15:30
Joined
Jan 11, 2013
Messages
3,912
In the combobox, I have code in an after update even to move to a specific record determined by the value selected in the combo box.
it would help to show the code.
Are you using FindFirst?
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 03:30
Joined
May 7, 2009
Messages
19,229
see post #2, you need to Bound your combobox to a Field.
when you do that the value of the combo is saved together with the record.
moving from one record to another, changes the value of your combo automatically.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 15:30
Joined
Feb 19, 2002
Messages
43,231
If you are using a combo to filter the form:
1. use an unbound combo
2. add criteria to your RecordSource query - select ... from ... Where somefield = Forms!myform!mycombo
3. use Me.Requery in the Click event of the combo.

When the form opens initially, it will open empty since there is no value in the unbound combo.
 

tmyers

Well-known member
Local time
Today, 15:30
Joined
Sep 8, 2020
Messages
1,090
In the process of trying to do this, I ended up cleaning up a few things. One of which was my "main" form and its recordsource. It was done in a sloppy manner. Once I cleaned that up, the wizard allowed me to use the combo to navigate records and is working wonderfully so far.
 

Users who are viewing this thread

Top Bottom