I have written (also somewhat leveraged) this code to pull info from an excel 2007 file. I step through the code and it works fine. I create an executable and it works fine. But if I open another instance of the executable, either on my computer or somebody elses, I get this error.
run-time error '-2xxxxxxxxxxxxxxxx'
ODBC excel driver] could not use '(unknown)'; file already in use.
Public rst As ADODB.Recordset
Public cnn As ADODB.Connection
Private Sub cmdQuit_Click()
Set rst = Nothing
cnn.Close
Set cnn = Nothing
Unload Me
End Sub
Private Sub cmdRS_Click()
Dim sConn As String, sSQL As String
Dim sPath As String, sDB As String
If Len(Me.txtAssyNum) <> 0 Then
AssyNum = frmMain.txtAssyNum
Else
MsgBox "Please enter an Assembly Number"
frmMain.Hide
Exit Sub
End If
sPath = "\\namp-dsk-002\Eng\Common Area\Ernest H"
sDB = "BH RI defects 04_11_12.xlsx"
Set cnn = New ADODB.Connection
sConn = "Provider=MSDASQL.1;"
sConn = sConn & "Persist Security Info=False;"
sConn = sConn & "Extended Properties=""DSN=Excel Files;"
sConn = sConn & "ReadOnly=True;"
sConn = sConn & "DBQ=" & sPath & "\" & sDB & ";"
sConn = sConn & "DefaultDir=" & sPath & ";"
sConn = sConn & "DriverId=790;MaxBufferSize=2048;PageTimeout=5;"""
cnn.Open sConn
Set rst = New ADODB.Recordset
sSQL = "SELECT TOP 15 QN, Defect, count(defect) as Num_of_Defects"
sSQL = sSQL & " From [QN Raw Data$] "
sSQL = sSQL & " WHERE board = " & Chr(39) & AssyNum & Chr(39)
sSQL = sSQL & " group by qn, defect"
sSQL = sSQL & " order by count(defect) desc, qn"
rst.Open sSQL, cnn, adOpenStatic
Set MyGrid.DataSource = rst
MyGrid.Columns(0).Width = 2000
MyGrid.Columns(1).Width = 2000
MyGrid.Columns(2).Width = 2000
MyGrid.ScrollBars = dbgAutomatic
End Sub
any help would be greatly appreciated..
Ernest
Be Alert, America needs more lerts
run-time error '-2xxxxxxxxxxxxxxxx'
ODBC excel driver] could not use '(unknown)'; file already in use.
Public rst As ADODB.Recordset
Public cnn As ADODB.Connection
Private Sub cmdQuit_Click()
Set rst = Nothing
cnn.Close
Set cnn = Nothing
Unload Me
End Sub
Private Sub cmdRS_Click()
Dim sConn As String, sSQL As String
Dim sPath As String, sDB As String
If Len(Me.txtAssyNum) <> 0 Then
AssyNum = frmMain.txtAssyNum
Else
MsgBox "Please enter an Assembly Number"
frmMain.Hide
Exit Sub
End If
sPath = "\\namp-dsk-002\Eng\Common Area\Ernest H"
sDB = "BH RI defects 04_11_12.xlsx"
Set cnn = New ADODB.Connection
sConn = "Provider=MSDASQL.1;"
sConn = sConn & "Persist Security Info=False;"
sConn = sConn & "Extended Properties=""DSN=Excel Files;"
sConn = sConn & "ReadOnly=True;"
sConn = sConn & "DBQ=" & sPath & "\" & sDB & ";"
sConn = sConn & "DefaultDir=" & sPath & ";"
sConn = sConn & "DriverId=790;MaxBufferSize=2048;PageTimeout=5;"""
cnn.Open sConn
Set rst = New ADODB.Recordset
sSQL = "SELECT TOP 15 QN, Defect, count(defect) as Num_of_Defects"
sSQL = sSQL & " From [QN Raw Data$] "
sSQL = sSQL & " WHERE board = " & Chr(39) & AssyNum & Chr(39)
sSQL = sSQL & " group by qn, defect"
sSQL = sSQL & " order by count(defect) desc, qn"
rst.Open sSQL, cnn, adOpenStatic
Set MyGrid.DataSource = rst
MyGrid.Columns(0).Width = 2000
MyGrid.Columns(1).Width = 2000
MyGrid.Columns(2).Width = 2000
MyGrid.ScrollBars = dbgAutomatic
End Sub
any help would be greatly appreciated..
Ernest
Be Alert, America needs more lerts