Solved

common method for database connection?

Posted on 2001-06-12
2
153 Views
Last Modified: 2010-05-02
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
Comment
Question by:rajani50
2 Comments
 
LVL 5

Accepted Solution

by:
dtomyn earned 20 total points
ID: 6184214
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
 

Author Comment

by:rajani50
ID: 6184325
thanks for ur reply
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Paint/Redraw window while dragging 16 77
Excel - Save a copy of work book 13 84
How does CurrentUser work? 10 37
Convert VB6 MSXML2.ServerXMLHTTP process to C# 2 46
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question