To join Ms-Access to VB try to write my code please help me

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • alem
    New Member
    • Dec 2006
    • 38

    To join Ms-Access to VB try to write my code please help me

    Hi all

    i could not joine MS Access table to VB the code i write below

    Private Sub Form_Load()
    Set cn = New ADODB.connectio n
    cn.Provider = "Microsoft.jet. oledb.4.0"
    cn.Open "C:\db1.mdb "
    Set rs = New ADODB.Recordset
    rs.Open "tbl", cn, adOpenDynamic, adLockOptimisti c
    Show
    Call DisplayTheCurre ntRecord
    End Sub


    My Database name is db1 and table name tbl.

    Please help me.
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    what is the error message ?

    try to use this sapmle for referrence for connection string

    cn.open "Provider=Micro soft.Jet.OLEDB. 4.0;Data Source=C:\Progr am Files\Microsoft Visual Studio\VB98\bib lio.mdb;Persist Security Info=False
    "

    Comment

    • jimmylee
      New Member
      • Feb 2008
      • 17

      #3
      Originally posted by alem
      Hi all

      i could not joine MS Access table to VB the code i write below

      Private Sub Form_Load()
      Set cn = New ADODB.connectio n
      cn.Provider = "Microsoft.jet. oledb.4.0"
      cn.Open "C:\db1.mdb "
      Set rs = New ADODB.Recordset
      rs.Open "tbl", cn, adOpenDynamic, adLockOptimisti c
      Show
      Call DisplayTheCurre ntRecord
      End Sub


      My Database name is db1 and table name tbl.

      Please help me.

      you have to change
      rs.Open "select * from tbl", cn, adOpenDynamic, adLockOptimisti c

      Comment

      • dnb
        New Member
        • Jan 2008
        • 34

        #4
        First add 'Microsoft ActiveX Data objects library 2.0' from references
        First Save your project and database in the same folder.


        Public cn As ADODB.Connectio n

        Private Sub Form_Load()

        Set cn = New ADODB.Connectio n
        cn.Provider = "Microsoft.jet. oledb.4.0;"
        cn.ConnectionSt ring = App.Path & "/db1.mdb"
        cn.CursorLocati on = adUseClient
        cn.Open

        Dim rs As ADODB.Recordset
        Set rs = New ADODB.Recordset
        If rs.State = 1 Then rs.Close
        rs.Open "select * from tbl", cn, adOpenDynamic, adLockOptimisti c

        End Sub

        Comment

        • alem
          New Member
          • Dec 2006
          • 38

          #5
          Alem
          I Thank U all I have got my answer
          I appreciate your help.

          Thanks again.

          Comment

          • debasisdas
            Recognized Expert Expert
            • Dec 2006
            • 8119

            #6
            Originally posted by jimmylee
            you have to change
            rs.Open "select * from tbl", cn, adOpenDynamic, adLockOptimisti c
            not necessary

            it can be any sql query, table ,view or materialized view name also.

            Comment

            Working...