Click to See Complete Forum and Search --> : Accessing two fields from same table
mikki
Aug 21st, 2000, 10:22 AM
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?
Dr_Evil
Aug 21st, 2000, 11:33 AM
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.
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
mikki
Aug 21st, 2000, 12:22 PM
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 = ""
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.