Click to See Complete Forum and Search --> : DAO help


February 18th, 2000, 03:50 PM
Hi,

I´d like to open an Access Database throught DAO in VB. If I declare a Database in Visual Basic, dim db as Database, the compiler generates a warning, because the Object couldn´t be found. (also not in the Object Catalog) How can I set up VB in order to use DAO?
Also, I just have to read a recordset from a table. Should I use a snapshot (I dpn´t have to modify a record, just sort them)? Where can I get some really basic VB Code on this Subjet?



thanks, Sebastian

Johnny101
February 18th, 2000, 05:05 PM
First you have to set a reference to the Microsoft DAO 3.51 Object Library (the version depends on your system 2.5 through 4.0) by going to the Project Menu then References. Then you can do the following:

private Sub Form_Load()
Dim db as Database
Dim rs as Recordset
dim sql as string

set db = Opendatabase("C:\Program Files\Microsoft Visual Studio\VB98\biblio.mdb")

sql = "SELECT * FROM Authors"

set rs = db.openrecordset(sql, dbOpenSnapShot)

MsgBox rs.Fields(1)

rs.close
End Sub




Hope this helps,
John

John Pirkey
MCSD
www.ShallowWaterSystems.com