Solved Combobox Changing Value (1 Viewer)

VBA-ish

Registered User.
Local time
Yesterday, 21:57
Joined
Aug 8, 2016
Messages
16
I have a form with several comboboxes that pull their values from another form. Everything works as expected except for one particular combobox. Its bound column is set to reference a listbox (whose data is populated by a field in a table with a long integer datatype.) The variable used to store the data is declared as a long integer type and when I msgbox the variable immediately prior to setting the combobox's value it returns what I expect. The problem is that the combobox is returning a different value, specifically, the next row in the table instead of the row with the value the msgbox is returning. I've never had this happen before and I'm at my wit's end trying to figure out why this is occurring. Hopefully that makes sense. Any thoughts?

Thanks in advance.
 

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 21:57
Joined
Feb 19, 2002
Messages
42,981
I have a form with several comboboxes that pull their values from another form
Forms don't store data. Tables store data so I'm not sure what this means. Are you saying that the RowSource's of the combos have criteria that references a different form?
 

Isaac

Lifelong Learner
Local time
Yesterday, 18:57
Joined
Mar 14, 2017
Messages
8,738
Definitely need more information on this one.

What in the world does this mean:
Its bound column is set to reference a listbox (whose data is populated by a field in a table with a long integer datatype.)

If it's bound, that means it's bound to a table or query. How exactly can it be 'bound' to another control?

- What's the Rowsource of the combobox
- What's the RowsourceType of the combobox
- What's the combobox's Column Count property
- What's the combobox's Bound Column property
 

VBA-ish

Registered User.
Local time
Yesterday, 21:57
Joined
Aug 8, 2016
Messages
16
Forms don't store data. Tables store data so I'm not sure what this means. Are you saying that the RowSource's of the combos have criteria that references a different form?
I stated that it's coming from the table with the field set to long integer that the listbox is pulling from and that the variable being used to store that data is also set to long integer. When I msgbox the variable to see what it's returning it's what I expect it to be. Sorry if it's worded strangely.
 

VBA-ish

Registered User.
Local time
Yesterday, 21:57
Joined
Aug 8, 2016
Messages
16
Definitely need more information on this one.

What in the world does this mean:


If it's bound, that means it's bound to a table or query. How exactly can it be 'bound' to another control?

- What's the Rowsource of the combobox
- What's the RowsourceType of the combobox
- What's the combobox's Column Count property
- What's the combobox's Bound Column property
I could have worded it better, see my previous response. Prior to opening the second form the current row's data in the listbox (its query) is stored in public variables which are then passed to the second form. The controls in the second form are set during the form's load event. I've double- and triple-checked the combobox's properties and they're all correct.
 

VBA-ish

Registered User.
Local time
Yesterday, 21:57
Joined
Aug 8, 2016
Messages
16
I'm having trouble articulating this because I've been staring at this for the past couple hours and it's giving me a headache. I'll try to break this down it its simplest form. I have a combobox on a form that is set during the form's load event using a public variable which stores a value from a query prior to that form loading. The datatype in the table is long integer and the variable is declared as a long integer. When msgboxed it returns the value I expect it to. The combobox's bound column is set to 0 which is the ID field of the table where the data is originating. When the form loads the combobox returns an incorrect value. Every other combobox on the form is done the same way and all work as expected, that is why I'm losing my mind over this.
 

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 21:57
Joined
Feb 19, 2002
Messages
42,981
You can't set values prior to the form loading. We can't see your code so we don't know what is happening. If you are trying to use the form to create a new record, it is best to NOT dirty the form until the user types the first character. That way, in the form's BeforeInsert event, you can put the value in the combo and continue as normal. This has the added advantage of allowing the user to insert multiple records and have the combo populated for each one, not just the first one.
 

moke123

AWF VIP
Local time
Yesterday, 21:57
Joined
Jan 11, 2013
Messages
3,852
Might be easier if you post a sample database.
 

VBA-ish

Registered User.
Local time
Yesterday, 21:57
Joined
Aug 8, 2016
Messages
16
I stepped away from this and just came back to it. I was running an update query generated from a userform which populated the current data from a table upon loading and allowed a user to modify values then update the table. I'm glad I worked on something else for a while because I just went back to it and instantly found the problem. I'd changed a field's name a while back slightly due to some other changes I'd made and I was trying to update the old field that didn't exist (it was close enough that I didn't notice it). I know it's not a great idea to change field names on the fly but I had to make some changes and the naming convention had to be modified to avoid confusion (ironic). Anyway, it works perfectly now. Thanks to everyone who offered help.
 

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 21:57
Joined
Feb 19, 2002
Messages
42,981
Just FYI, Userforms are not used in Access. If you search for info on Userforms it may be invalid for Access forms.
 

Users who are viewing this thread

Top Bottom