bfreescott
Board Regular
- Joined
- Aug 6, 2015
- Messages
- 115
I'm using an ado connection to query data from excel files on a shared network drive and I'm getting the standard "File in Use" message whenever another user has the file already open. Is that to be expected? My purpose in using ADO was two-fold: speed and being able to query a closed workbook. I suppose I didn't realize I would have the same issue I get when using Workbook.open. Is this a bug? Is there something wrong with my function? Workaround?
Code:
Function Get_Initial_VPK_Advance(wbName As String) As Variant
'
On Error GoTo ErrorHandler
Dim Conn As ADODB.Connection
Dim ConnString As String
Dim rs As New ADODB.Recordset
ConnString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & wbName & ";Extended Properties=Excel 12.0;"
Set Conn = New ADODB.Connection
Conn.Open ConnString
If Not (Conn.State And 1) = 1 Then
MsgBox "Source data cannot be found. Please check the location of the file you are querying."
Set Conn = Nothing
Set rs = Nothing
Application.ScreenUpdating = True
Application.StatusBar = False
Exit Function
End If
rs.Open "SELECT * FROM InitialAdvance", Conn, adOpenStatic, adLockReadOnly, adCmdText
If Not rs.Fields(0).Value = Null Then
Get_Initial_VPK_Advance = rs.Fields(0).Value
End If
rs.Close
Conn.Close
Set Conn = Nothing
Set rs = Nothing
Exit Function
ErrorHandler:
MsgBox "Error: " & Err.Number & " , " & Err.Description & Chr(13) & _
"Procedure is: Get_Initial_VPK_Advance" & Chr(13) & ""
rs.Close
Conn.Close
Set Conn = Nothing
Set rs = Nothing
Application.ScreenUpdating = True
Application.StatusBar = False
'
End Function
Last edited: