how to?

mohammadagul

PrinceAtif
Local time
Today, 09:15
Joined
Mar 14, 2004
Messages
298
hi,

i know this does not concern access but i dont know where to post this question.

in access we have table whihc holds data in them. from these table we create queries and then form.

but

unlike in access in vb we directly develop forms. (i hope i am right). now my question.

how do i connect my VB form to my Tables. regardless they are in Access or Somewhere else.?
 
In your VB form code, you have to use DAO or ADO routines to open the database and then open the recordset you want, then on the VB event that is equivalent to Access FormCurrent, reload your controls from the recordset.

Or something similar to that.
 
Here's a typical ADO example.

Remember that in Visual Basic you have to create a connection string to the database unlike Access which is, by default, connected to Jet.

Code:
    Dim cn As New ADODB.Connection
    Dim rs As New ADODB.Recordset
    Const Connection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
    Const DataSource = "C:\MyDatabase.mdb"
    cn.ConnectionString = Connection & DataSource
    cn.Open
    rs.Source = "SELECT * FROM MyTable;"
    rs.CursorType = adOpenForwardOnly
    rs.ActiveConnection = cn
    rs.Open
    Do While Not rs.EOF
        Debug.Print rs.Fields("MyField").Value
        rs.MoveNext
    Loop
    rs.Close
    Set rs = Nothing
    cn.Close
    Set cn = Nothing
 

Users who are viewing this thread

Back
Top Bottom