Results 1 to 4 of 4

Thread: Connection to access DB

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2005
    Posts
    15

    Connection to access DB

    Hello ...
    I am a new member .. and a newbie ....
    and I would like some one to help me please ...
    how can I connect from vb 6.0 to access database by coding ... (not by using the Data Object (I mean the control)) ...

    thank you very much ....

  2. #2

  3. #3
    Lively Member
    Join Date
    Jul 2002
    Posts
    78

    Re: Connection to access DB

    Hi Prototype,

    I use ADO to connect to an Access 2002 database, here is the code I use

    VB Code:
    1. 'String used to connect to the SRT database -- this allows for network use in the future
    2. 'Keep in module so that only module needs to be changed when database is moved
    3.     Public cnSRTDB As String
    4. 'main SRT database
    5.     Public SRT_DBcn As ADODB.Connection
    6.     Public cmdSRT_DB As ADODB.Command
    7.  
    8. Public Sub Open_SRTDB()
    9. 'set connection and open SRT database
    10.     Set SRT_DBcn = New ADODB.Connection
    11.     cnSRTDB = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & App.Path & "\SRT_DB.mdb; Persist Security Info=False"
    12.     SRT_DBcn.Open cnSRTDB
    13. End Sub
    14.  
    15. Public Sub Close_SRTDB()
    16. 'close database and set to nothing
    17.     If SRT_DBcn.State <> adStateClosed Then
    18.         SRT_DBcn.Close
    19.         Set SRT_DBcn = Nothing
    20.     End If
    21. End Sub

    I have this in a module and call the open and close when I need to. This allows me the flexibility to change the database connection from one place only -- we are planning on migrating to Oracle later.

    Hope this helps!

  4. #4
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: Connection to access DB

    Prototype,

    Look here for a working example

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width