PDA

Click to See Complete Forum and Search --> : Using Access database


Publi-X
Sep 24th, 1999, 01:10 PM
Anyone know how to use access queries from visual basic using code. Any information on using code and access database is welcome. How to lock a db, etc.

Jaspal
Sep 24th, 1999, 07:24 PM
Add a reference to DAO 3.51 object library from the project menu.

Then write the foll. routine in your project

Sub InitDB()

Dim WS as Workspace
Dim DB as Database
Dim RS as Recordset

Set WS = DBEngine.Workspaces(0)
Set DB = WS.Opendatabase("C:\MyData.mdb")

Set RS=DB.OpenRecordset("Select * from Employee where EmpNo = 10")

With RS
Text1= .fields("EmpNo")
Text2= .fields("EmpName")
Text3= .fields("Address")
Text4= .fields("Phone")

End With

End Sub


Add 4 text boxes and call initdb in your form load event after filling the database with some values

To add values in the database use .Addnew and .Update