• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 191
  • Last Modified:

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
0
crush_Of_Hearts
Asked:
crush_Of_Hearts
1 Solution
 
saka123Commented:
Hi there ,

That can be done by atleast two ways . Either use a data control (from the standard vb tool bar ) and set connect , Database and recordsource properties for the control so that it can pick data from the required table . Give path of database and name of table in recordsource . Bind the textboxes to the datasource and link then to a particular field of database .

Second approach , Link thru code . Initially use the wizards . From the Add-Ins  add " VB6 Data form wizard " . Then choose Access and give path for the database and then the table name .
A few clicks of next button and a fully functional vb form is generated . Study the form load code to see the code used for linking thru code .

I think this will help . Do keep me posted with the latest .

Raman Saka
0
 
johnmhatCommented:
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.  
0
 
richardlouieCommented:
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.
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now