Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I pass the Control of the DATA CONTROL to a combo box ?

Status
Not open for further replies.

FrankCosta

Technical User
Oct 31, 2001
3
CA
K here's the scoop I'm new/learning Visual Basic and would appreciate some help on this.

How do I pass the Control of the DATA CONTROL to a combo box ?

What I want to do is Select an Option from the COMBO Box and have all the other fields updated instead of pressing the DATACONTROL once for the next record, I want to Select the record with the combo box.

I'm using MS Access for the database.

Hope it was a good explanation.

Thanks
 
Can you post a sample of your code?
-----------------------------------------------
"The night sky over the planet Krikkit is the least interesting sight in the entire universe."
-Hitch Hiker's Guide To The Galaxy
 
I don't have any code written yet, I wanted some opinions of what the best way would be.

I'm just a beginner, so any help would be great.
 
I believe (if I understand your question correctly), that the best way to navigate through a recordset is not by using a data control, but by setting all of your connections in code. For example:

Private Sub Form_Load()

dim con as adodb.connection 'declares database connection
set con = new adodb.connection
dim rs as adodb.recordset 'declares recordset
set rs = new adodb.connection

with con
.ConnectionString = app.path & "\databaseName.mdb"
.Provide = "Microsoft.Jet.4.0"
.Open
end with

End Sub

Public Sub SetRS(SQL)

with rs
.ActiveConnection = con
.Source = SQL
.Open
end with

End Sub

On the Form_Load event, the connection to the database is made (assuming that your database is in the same folder as your program). What you can do with the SetRS function (it should probably be put into a module), is something like the following:

Assume that there are three text boxes on your form, and you'd like them to be updated when the user selects an option from the combo box. One's name is "Name", another is "Sex", and the third is "PhoneNumber". Assume also that the database fields are under the same name as the text fields, and that you are making your selection by the field's ID (table name is tblUsers).

Private Sub ComboBox_OnClick()

SetRS "SELECT * FROM tblUsers WHERE ID = " & ComboBox.text
Name.Text = rs.Fields("Name")
Sex.Text = rs.fields("Sex")
PhoneNumber.Text = rs.Fields("PhoneNumber")

End Sub

The "SQL" argument for the SetRS function allows you to set the recordset to your exact needs. So every time you need something different, you can call that SetRS function with a different SQL statement. Hope this is the kind of thing that you were looking for.
-----------------------------------------------
"The night sky over the planet Krikkit is the least interesting sight in the entire universe."
-Hitch Hiker's Guide To The Galaxy
 
This is what i have been looking for..When i try and run your code i get and error on Set rs = new adodb.connection. the error says type mismatch..

I am also using access 97..what would the line be for that engine...i tryed Microsoft.Jet.3.51" is this correct??

Thanks DVannoy
A+,Network+,CNA
dvannoy@onyxes.com
 
Sorry, my fault. In the above code, the line:

set rs = new adodb.connection

Should in fact be:

set rs = new adodb.recordset

That's why you were getting the type mismatch error. DVannoy - I believe that is the correct engine (sorry, haven't used Access97 for anything myself)



-----------------------------------------------
"The night sky over the planet Krikkit is the least interesting sight in the entire universe."
-Hitch Hiker's Guide To The Galaxy
 
ok now it connects...i am using a datacombo for this...should i just use a standard combo?..once i click on the combo box i get this error :

run-time error 424 object required..

then if i debug it goes to this line of code..

.ActiveConnection = con

should this code be in a seperate module??

Public Sub SetRS(SQL)

With rs
.ActiveConnection = cnn1
.Source = SQL
.Open
End With

End Sub

any help would be appreciated..

DVannoy
A+,Network+,CNA
dvannoy@onyxes.com
 
I wanted some help.I have made my database in access and linked it to visual basic using adodb and wanted to know how i could add the search command to my project.


Regards
 
Hi there.

I've tried this ado stuff, but it says 'not definied' for this : dim con As adodb.Connection, but the MS DAO library is added. So if anyone could help me that would be fine.

Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top