Link to home
Start Free TrialLog in
Avatar of crush_Of_Hearts
crush_Of_Hearts

asked on

linking visual basic and acces databases(tables)

i have developed my programs in vb and i want the to use tables from access how can i do it
ASKER CERTIFIED SOLUTION
Avatar of saka123
saka123

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of johnmhat
johnmhat

Crush,
What are you trying to do?  Raman is correct, however, binding the controls to the database at design time can limit the scope of those controls.  I think the second suggestion may work for you better if you want the controls to have some range.  
In VB, click on Project->References on the menubar; select the "Micorsoft DAO 3.6 Object Library"

- Create a MS Access database 'dbase.mdb'.
- Create a table 'tab_ship' with the following fields:
    Field      Data Type
    -----      ---------
    name       text
    state      text
    status     text

- Add a few records, some with status = 'Send'.

- Then add the following code to you VB project:

----------------------------------------

Dim wrkDefault As Workspace
Dim dbsDB      As Database
Dim rsTable    As Recordset
Dim sQuery     As String

    ' Get the Workspace.
    Set wrkDefault = CreateWorkspace("", "admin", "", dbUseJet)
   
    ' Open the database
    Set dbsDB = wrkDefault.OpenDatabase(".\dbase.mdb")

    ' Set the query
    sQuery = "SELECT name, state, status " & _
             "   FROM tab_ship " & _
             "   WHERE status = 'Send'"

    ' Set the recordset.
    Set rsTable = dbsDB.OpenRecordset(sQuery)

    ' Browse through the recordset
    While Not rsArea.EOF
        sName   = rsTable.Fields(0)
        sState  = rsTable.Fields(1)
        sStatus = rsTable.Fields(2)
    Wend

----------------------------------------

The above is pretty flexible.  You can change sQuery to do inserts, updates, and deletes of records in the table.