Results 1 to 2 of 2

Thread: A stupid/basic question

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2000
    Posts
    343

    Exclamation Ado connect question

    I want to connect to a database ONCE (Like in the formload procedure), do my sql statements in other procedures like command button clicks etc and then close the connection once I click exit ie. My connect, execute of sql statements and close are all in different procedures!!

    How can I make all procedures see the connection, recordset etc I set up in form load????? Am I falling of the bus here??

    I connect as follows.... but when I want to do a cnconnect.execute (ssql) in the "save" click event, I get an error that I need an open connection etc.

    public sub form_load()

    Dim cnConnect As Connection
    Dim rsRecord As Recordset
    Dim adoErr As Error

    Set cnConnect = New Connection

    On Error GoTo ConnectError
    With cnConnect
    .Provider = "microsoft.jet.OLEDB.4.0"
    .ConnectionString = "user id=admin;password=; " & _
    "data source=c:\settadminsystem\Sett.mdb; "
    .Open
    End With


    Exit Sub
    ConnectError:
    For Each adoErr In cnConnect.Errors
    MsgBox "ERROR LOGGING IN " & adoErr.Description, vbCritical, "LOGIN"
    Next


  2. #2
    Frenzied Member
    Join Date
    Aug 1999
    Location
    Santa Clara, Ca , 95058
    Posts
    1,105
    change

    Dim cnConnect As Connection


    to

    Public cnConnect As Connection

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