Click to See Complete Forum and Search --> : specifying the database to query
Okay, this may sound ignorant, but I'm having a prob getting my VB project to recognize the Access database as where all SQL queries are to hit. Everything I've read in Help & Mastering VB 6.0 shows sample code of client side applications hitting a SQL DB on a server somewhere. My Access database is on the same computer where the VB project stays. How do I define this database (only one table) as the source for the one SQL query string in my code?
Serge
Dec 14th, 1999, 08:20 AM
You can use DAO object library. Add a reference to Microsoft DAO library 3.51 (or select the highest version you have installed on your computer). Also, add a listbox to your form. Then you can use this code:
Dim db As Database
Dim rs As Recordset
Set db = Workspaces(0).OpenDatabase("C:\MyDB.mdb") 'Change this to appropriate path
Set rs = db.OpenRecordset("MyTable", dbopenTable)
Do Until rs.EOF
List1.AddItem rs("Name")
rs.MoveNext
Loop
Assuming that I have a table called MyTable and a field in that table called Name.
------------------
Serge
Software Developer
Serge_Dymkov@vertexinc.com
Access8484@aol.com
ICQ#: 51055819 (http://www.icq.com/51055819)
[This message has been edited by Serge (edited 12-14-1999).]
Gimpster
Dec 14th, 1999, 10:29 PM
I don't know a whole lot about Access databases, but do they accept SQL statements? Or do they have their own set of codes? You might look into that.
------------------
Ryan
corneslen@hotmail.com
ICQ# 47799046
[This message has been edited by Gimpster (edited 12-15-1999).]
JHausmann
Dec 15th, 1999, 05:29 AM
Yes, Access accepts SQL.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.