Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Connection Cannot Be Used to Perform this Operation

Hey there,

I am gettinga very frustrating error which, no matter what I try,
cannot be shifted. It is the dreaded "connection cannot be used" but
as far as I can see (and this has only suddenly stopped working) there
is nothing that has changed. The error appears when the condb.open
statement passes, giving "Unspecified Error" and then when the
recordset is opened usig this db connection. The code is as follows:

Dim conDB As ADODB.Connection

Const DatabasePath As String = "C:\Working\db1.mdb"

Sub SetUpConnection()
On Error GoTo Errhandler
Set conDB = New Connection
conDB.Provider = "Microsoft.Jet.OLEDB.4.0" 'Change to 3.51 for
Access 97
conDB.ConnectionString = DatabasePath
conDB.Open
Exit Sub
Errhandler:
MsgBox Err.Description, vbExclamation, "An error occurred"
End Sub

Public Function funcGetAcctDesc(strAcctDest As String) As String
Dim rsLookup As ADODB.Recordset
Dim strSQL As String
On Error GoTo Errhandler
If conDB Is Nothing Then SetUpConnection
If (strAcctDest < "") Then
Set rsLookup = New ADODB.Recordset
strSQL = "SELECT tAcctMain.amCode, tAcctMain.amDesc " & _
"FROM tAcctMain " & _
"WHERE (tAcctMain.amCode = '" & strAcctDest & "') " & _
"ORDER BY tAcctMain.amCode DESC"
rsLookup.Open strSQL, conDB, adOpenForwardOnly, adLockReadOnly
If rsLookup.BOF And rsLookup.EOF Then
funcGetAcctDesc = ""
Else
funcGetAcctDesc = rsLookup.Fields("amDesc").Value
End If
rsLookup.Close
Set rsLookup = Nothing
Exit Function
Else
funcGetAcctDesc = ""
End If
Exit Function
Errhandler:
MsgBox Err.Description, vbExclamation, "An error occurred"
End Function

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is there a function to perform this operation? Ayo Excel Discussion (Misc queries) 2 July 17th 09 03:17 AM
always recheck data connection library for latest connection strin FurmanGG Excel Discussion (Misc queries) 0 September 14th 07 04:48 PM
Change cut/paste operation to cut/insert operation Don Guillett Excel Programming 0 January 17th 07 03:23 PM
Complex Macro to perform an operation as it steps down cells? Jeni Q Excel Worksheet Functions 0 August 25th 05 04:38 PM
microsoft outlook unable to perform operation - send = receive. heibner Excel Discussion (Misc queries) 1 July 13th 05 09:05 AM


All times are GMT +1. The time now is 09:11 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"