Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

AutoSelect the first entry in a combo box

Status
Not open for further replies.
Joined
Jun 16, 2005
Messages
12
Location
US
Hi Everyone,

I have two combo boxes on my form. When the user makes a selection, I want the focus to move to the second combo box. This is simple enough.

However, is there a simple way to have Access automatically select the first entry in the second combo box, rather than having the users select it on their own? How would I accomplish that?

Thanks
 
Me!yourCombo2.SetFocus
Me!yourCombo2.Value = Me!yourCombo2(0)

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 

This didn't work. I got the message:

"Property let Procedure not defined and property get procedure did not return an object"

??
 
This is simple enough
Could you please post how you do that ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
I think PHV just forgot the .ItemData propety:
[tt]Me!yourCombo2.Value = Me!yourCombo2.ItemData(0)[/tt]

Roy-Vidar
 
Another way:
Me!yourCombo2.SetFocus
Me!yourCombo2.ListIndex = 0

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Sure,

Save_Referral:
DoCmd.RunCommand acCmdSaveRecord
If [Reason] = "NP / LC = No Preference / Lowest Cost" Then GoTo Provider_byDate Else GoTo Provider_byCounty

Provider_byDate:

[Vendor].SetFocus

After the last line is where I tried your code suggestion. It did not work. If I am reading your code properly, isn't it setting the value of the combo box to zero? If so, this would result in a type mismatch since the combo box is storing text. This is in fact what happened when I tried to take out the Me! portion of the command.

I simply want the first entry in the list to be automatically entered. I suppose I could use a Sendkeys statement, but in this case I think that would be highly unreliable.

Any thoughts?
 
So:
[Vendor].SetFocus
' One way
[Vendor].Value = [Vendor].ItemData(0)
' another way
[Vendor].ListIndex = 0

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
O.K. I tried the second approach with limited success.

Here's the total story.

I have a filter on the drop-down list that causes the list to show only those vendors from the consumer's county. The county is on the main form. It appears (I could be wrong) as if your second approach is pulling from the underlying record source and ignoring the filter.

 
I have a filter on the drop-down list
How you do that ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Whoa, we have a winner.

[Vendor].Value = [Vendor].ItemData(1)

I had to change the zero value to 1. When zero, it pulled the column heading. Although, if I had column headings turned off, I wonder if it would have worked? No bother...thanks for the help. You're a life saver.

 
Oh, by the way. to answer your last question. The filter is simply being applied to the underlying SQL query in the Row Source of the combo box.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top