Setting combo box value after update

  • Thread starter Thread starter JustinP
  • Start date Start date
J

JustinP

I have two combo boxes:

cboSector
cboSite

The control source for cboSector is a value list
The control source for cboSite is a query

When the user selects a value from cboSector, the cboSite requeries and
that works fine. What I also need is when the user select a value from
cboSite I need cboSector.Value to show the value from a query (but not
requery the actual control source of the combo box itself).

Below is the AfterUpdate of cboSite. The query sqlSector is the correct
query I want to look up, but how do I set the value of cboSector.Value
to the value from the query.

40 If cboSite.Value <> "Any" And cboSector.Value = "Any" Then

50 sqlSector = "SELECT SECTOR FROM Vege_Parameter WHERE SITE_ID =
'" & cboSite.Value & "'"
60 cboSector.Value = sqlSector

70 End If

Please ask if it is unclear.
 
Hello Justin.

JustinP said:
I have two combo boxes:

cboSector
cboSite

The control source for cboSector is a value list
The control source for cboSite is a query

When the user selects a value from cboSector, the cboSite requeries
and that works fine. What I also need is when the user select a value
from cboSite I need cboSector.Value to show the value from a query
(but not requery the actual control source of the combo box itself).

Below is the AfterUpdate of cboSite. The query sqlSector is the
correct query I want to look up, but how do I set the value of
cboSector.Value to the value from the query.

40 If cboSite.Value <> "Any" And cboSector.Value = "Any" Then

50 sqlSector = "SELECT SECTOR FROM Vege_Parameter WHERE" & _
" SITE_ID = '" & cboSite.Value & "'"
60 cboSector.Value = sqlSector

70 End If

Please ask if it is unclear.

To start with, you can use the dlookup function:
cboSector.Value = DLookup("SECTOR", "Vege_Parameter", & _
BuildCriteria("SITE_ID", dbText, cboSite.Value))
When you get more experienced, you will notice that DLookup is very
slow, and you will make your own DLookup function using dao or ado.
 
Back
Top