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 Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Removing an old value of a combobox

Status
Not open for further replies.

terraman

Programmer
May 26, 2003
12
NL
Hi all,

I'm rather new to vba coding and I got two comboboxes. (in fact 3 but the third should work the same as the second so that doesn't matter)
The second combobox is being filled by the first combobox so when I select a type in the first, all subtypes in the second show. I used a query for the second combobox and when I update the first combobox I requery.
It works fine, exept one point. The second combo box updates but keeps the old value as a selection inside. How can I remove the old value and set the selection to the first new value?

Thanks
 
That;s what I did.

The first combobox has got the following after update:

Me!Combobox2.Requery
Me!ComboBox2.SetFocus

But When I select valua A in combobox1
The select value A1 in Combobox2
And then I select Value B in Combobox1

Combobox2 fills up with values matching the new combobox1 value, but it also inludes value A1 while that is not a value of option B of combobox 1.

Is my problem clear? Tell me if you need more info.

Thanks,
Johannes
 
By the way, I tried to set the value to empty firts and then requery, but he then makes the field really empty.And the requery doesn't set the value of the combobox to the first row.
Maybe there is an option to set the value to the first row?
 
Hi terraman,

It's a quiet day today. If you want, you can send me a copy of your DB. Remove any sensitive Records first. I'll have a look at it and post any suggestions here in this Thread. billpower@cwcom.net

Bill
 
I developed this sample with two combo boxes. The first catches the item in the selected value and fills the second all entries having that letter.

Private Sub Combo0_Click()
Dim SQL As String

SQL = "SELECT * FROM Table1 WHERE Table1.city = "
SQL = SQL & Chr(34) & Me.Combo0.Column(1) & Chr(34) & ";"
Me.Combo9.RowSource = SQL

End Sub

rollie@bwsys.net
 
Hi,

I've created a new Query qry_Stageplek the SQL is:

SELECT DISTINCT Stageplek
FROM Contract
WHERE (((Opleiding)=[Forms]![frmContract]![kzlOpleiding]));

This is basically getting the same info as the Recordsource for your TextBox kzlUniversiteit

In the AfterUpdate Event of kzlOpleiding the code now looks like this:

Me!kzlUniversiteit = DFirst("[Stageplek]", "qry_Stageplek")
Me!kzlUniversiteit.SetFocus

This is setting the Value of kzlUniversiteit to the first Record in the Query qry_Stageplek.

Hope this makes sense. Update in the Email.

Bill
 
This worked perfect, Thanks, just what I needed.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top