Can a combo box do this...

  • Thread starter Thread starter jake
  • Start date Start date
J

jake

if the data is in combo1 the following would happen.
combo1: user would select value from list
textbox1: would automactically fill in with city
textbox2: would automatically fill in with zip

if data is not in combo1 ->
combo1 - textbox1 - textbox2 -> allow user to type in values in each
of the three boxes

Thanks for your help,
Jake
 
The trick is to include the other columns in the combo, but set their widths
to 0 like:

Select ID, Company, Address, City, State, Zip From tblCompanies

Widths should be:

0"; 1.25"; 0";0";0";0"

And the text box for column 3 (address) would read like:

=cboCompany.Column(2)

the index being zero (0) based.
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads:
http://www.datastrat.com
http://www.mvps.org/access
 
Of course.
Assuming that your ComboBox, Text1 and Text2 are NOT bound to anything,
and there is MyTable having fields SearchField, CityName, Zipcode, put
the following in the AfterUpdate event of the combo box:

Dim Rst as ADODB.Recordset
if Me.ComboBox.NotInList
Set Rst = New ADODB.Recordset
Rst.Open "SELECT TOP 1 CityName, Zipcode FROM MyTable WHERE SearchField
= '" & Me.ComboBox & "'", _
CurrentProject.Connection, adOpenStatic, adLockReadOnly
if Rst.RecordCount <> 0 then
Me.Text1 = Rst.Fields(0)
Me.Text2 = Rst.Fields(1)
end if
Rst.Close
Set Rst = Nothing

Cheers,
Pavel
 
Back
Top