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

tmyers

Active member
Local time
Today, 04:11
Joined
Sep 8, 2020
Messages
493
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, 09:11
Joined
Jul 26, 2013
Messages
7,744
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

Active member
Local time
Today, 04:11
Joined
Sep 8, 2020
Messages
493
I will change from openform to gotorecord and see if that remedies the problem.
 

tmyers

Active member
Local time
Today, 04:11
Joined
Sep 8, 2020
Messages
493
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, 04:11
Joined
Jan 11, 2013
Messages
2,197
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

error reading drive A:
Local time
Today, 17:11
Joined
May 7, 2009
Messages
11,121
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, 04:11
Joined
Feb 19, 2002
Messages
30,570
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

Active member
Local time
Today, 04:11
Joined
Sep 8, 2020
Messages
493
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