|
-
Apr 12th, 2011, 02:49 PM
#1
Thread Starter
Lively Member
Recordset: Database Connection kind of working.
so i have this code that connects to the database and runs the sql query but because i log in using a userform then run the code.
I am getting the error message "the connection can not be used to perform this operation. It is either invalid or closed in this context"
but when i have MFcnn open it says "cant run operation when objects is open"
[code]
Public Sub Queries()
Dim rs As ADODB.Recordset
Dim cn As ADODB.Connection
Dim strSQL1 As String
Set rs = New ADODB.Recordset
Set cn = New ADODB.Connection
strSQL1 = "SELECT COUNT (INUNACPT) FROM AIS3AM4.KTPT80T WHERE CDPRODCO=RETAIL_MAP"
'With MFcnn
'.Provider = "IBMDADB2.DB2COPY1"
'.Mode = adReadWrite
'.ConnectionString = "Password=" & password & ";Persist Security Info=True;User ID=" & username & ";Data Source=" & DatabaseEnv & ";Mode=ReadWrite;"
'.Open
'End With
'cn.Open ConnectionString = "Password=" & password & ";Persist Security Info=True;User ID=" & username & ";Data Source=" & DatabaseEnv & ";Mode=ReadWrite;"
rs.Open strSQL1, cn
Index.Range("AC2").CopyFromRecordset rs
rs.Close
cn.Close
Set rs = Nothing
Set cn = Nothing
End Sub
[code]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|