Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 175
  • Last Modified:

common method for database connection?

I wrote the following code in my MDIForm load method.....This is my first loading form name.So i wrote
the common coneection here.
But when i run this application ..i got compilation error
like "Invalid attribute in sub or function"..
Can u help me from this please...
rgds,
rajani
Public Sub MDIForm_Load()
    Dim sConnect As String
    Public dfwConn As ADODB.Connection
    Dim cmd As ADODB.Command
     'set strings
        sConnect = "Provider=MSDASQL.1;Connect Timeout=15;Extended Properties='DSN=ACR;DBQ=c:\windows\desktop\ACRData.mdb;DriverId=281;FIL=MS Access;MaxBufferSize=2048;PageTimeout=5;UID=admin;';Locale Identifier=3081"
        ' open connection
        Set dfwConn = New Connection
        dfwConn.Open sConnect
        Set cmd = New Command
        cmd.ActiveConnection = dfwConn
        cmd.CommandType = adCmdStoredProc
     
End Sub
0
rajani50
Asked:
rajani50
1 Solution
 
dtomynCommented:
Move the line "Public dfwConn As ADODB.Connection" out of the sub procedure (put it in the General Declarations section).  That is, a procedure can not have declared within it a public variable.
0
 
rajani50Author Commented:
thanks for ur reply
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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