I would like to access two fields from the same table. When the user chooses a client from the data ComboBox then the ClientID text box should populate with the corresponding ID.
How do I do this?
Printable View
I would like to access two fields from the same table. When the user chooses a client from the data ComboBox then the ClientID text box should populate with the corresponding ID.
How do I do this?
You could use SQL to poulate your TextBox with the corresponding ClientID. Try using something like this. If you need me to ellaborate more let me know.
Code:
Dim cnn As Connection
Dim rs As Recordset
Set cnn = New Connection
Set rs = New Recordset
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\\yourDB.mdb;"
rs.Open "SELECT `ClientID` FROM `TableName` WHERE `client` = '" & cboClient.Text & "' ", cnn, adOpenStatic, adLockReadOnly
Set txtClientID.DataSource = rs
txtClientID.DataField = "ClientID" 'The field name from table.
rs.Close
cnn.Close
Set rs = Nothing
Hi Dr_Evil
I am trying to use ADO Find
Find does not support multiple column comparison. An alternative is to use the filter method(if you need to match rows based on 2 or more fields).
Here's how to use it:
rs.filter = "column1 = 'ABC' and column2 = 1"
if rs.eof then
msgbox "no matching rows"
else
msgbox rs!column3
end if
to reset,
rs.filter = ""