Click to See Complete Forum and Search --> : How would you all do this?
privateagentx
May 10th, 2001, 01:11 PM
Problem description: I need to load a record based on an alphanumeric primary key field of a table selected from a dropdown combo box. Then, i need a command button that when clicked, will display the record in the approriate text boxes. For example, the user will select a project number (alphanumeric) from a project table using a datacombo box. then, all the text boxes will populate with the appropriate fields from the table. I've tried numerous ways to do this to no avail. I'm a beginner at this so i would appreciate any help i can get. Thanks in advance.
Johnny101
May 10th, 2001, 01:22 PM
The combobox has a Click event. in there, grab what was selected (Combo1.List(Combo1.ListIndex)) will return to the text of the chosen. Now issue your SQL statement with this value as the WHERE clause. Once you get your recordset back - assign the text boxes their respective values.
if you need more detail - let me know.
john
John Pirkey
MCSD
http://www.ShallowWaterSystems.com
http://www.stlvbug.org
privateagentx
May 10th, 2001, 01:29 PM
Thanks for your reply Johnny. I've tried that, and I got errors, but I think my problem is that i'm trying to use ADO and haven't fully grasped the concept such as opening connections and stuff like that. So what i guess i'm saying is yes I do need more detail. Thanks again.
Johnny101
May 10th, 2001, 02:15 PM
well, something like this:
private Sub Combo1_Click()
dim sql as string
dim rs as adodb.recordset
sql = "SELECT * FROM YourTable WHERE ProductNumber = '" & Combo1.List(Combo1.Listindex) & "'" '
set rs = new adodb.recordset
set rs = YourConnectionObject.Execute(sql)
if not rs.eof then
txtProductName.Text = rs!ProductName
txtProductCode.Text = rs!ProductCode
txtProductPrice.Text = rs!ProductPrice
rs.close
end if
set rs = nothing
End Sub
something like that shoud work for what you want.
hope this helps,
john
John Pirkey
MCSD
http://www.ShallowWaterSystems.com
http://www.stlvbug.org
privateagentx
May 10th, 2001, 02:18 PM
thanks , I will try it. Let you know what happens!
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.