[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 372
  • Last Modified:

How do I set an initial combo box value when the source table is linked

Hi all,

I have a combo box which looks up employee names in a table. I would like to set the initial value of the combo (depending on which employee is using the system) on opening the form.

This is straightforward I know; me.combobox = "whoever"

I notice, however, that when I split the database, the combo box still works fine but no longer allows me to set an initial value. I could have sworn I have done this before with success. I am very confused...

Thanks in advance, John
0
JohnSaint
Asked:
JohnSaint
  • 3
2 Solutions
 
Jim Dettman (Microsoft MVP/ EE MVE)PresidentCommented:
John,

 There's no reason it should stop doing that unless you have limit to list set to yes and your default value is not in the table.

 A better approach is to use this:

=Forms![<myFormName>]![<myComboControName>].ItemData(0)

or

=Forms![<myFormName>]![<myComboControName>].ItemData(1)

  If you have column headings set to yes.

  This will default the combo to the first entry in the list if there is any data.

  Note: make sure you replace   "<myFormName>" and "<myComboControName>"  with your actual form and combo names.

Jim.
0
 
JohnSaintAuthor Commented:
It's odd.

I literally created the combo. It worked fine and set the default.

I split it and it stopped defaulting.

Try it yourself. I've attached the pre-split db. It works fine.
Spilt it and it loses the default.

I appreciate it if you don't want to but I'd be interested to see if you get the same results. Otherwise I will try your suggestions.
SplitDrop.accdb
0
 
mbizupCommented:
Jim's right about the Limit to List property.

Explaining what you are doing...

Your combo box is bound to the ID field in your table.  The IDs in your combobox define what the value is.

You are setting it to "John", which is not a valid ID.

If you set it to 1 (John's ID), which is in the list of IDs, it will work either in a split or non-split DB.

I am very surprised that setting the value of the combo to "John" worked at all.  I didn't know that was doable.

All that said, the method that Jim described above is my preferred method as well
0
 
JohnSaintAuthor Commented:
Hi Guys,

Jim, I don't want to default to the first item in the list, I want to set it to a specific value which will change depending on who logs in. That is a nice tip though, cheers.

Mbizup, you cracked it. It shouldn't really have let me do it in the first place and that was what stumped me. I can either set the initail value to the correct ID value or I can remove the ID select from the combo and just select on the Employee names. Both seem to work.

Jim, I'll have to give more points to Mbizup here but many thanks to you both. Great work again...
0
 
JohnSaintAuthor Commented:
Thanks
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now