I'm having problems getting an error when trying to open an access database that I can open most times, but when it doesn't open I get the error message: Cannot open database ", You may not have.... or Corrupt file (Something like that). If I close excel and reload then it will work for a while and then all of a sudden it quits again. I have about 8 computers running this same excel file over company network.
When program starts, it accesses 3 access 97' databases, 2 of which just pulls information in and 1 of which will record. It wall was working great but suddenly I just keep getting these errors. When I debug it doesn't help much. The only thing I can think of is when I'm pulling or pushing data to/from databases that when the other users are using it, it won't allow multiple user to access it???
After each procedure I set recordset and connection to nothing. Is that correct? Do I need to use a different way to access access when I have multiple users?
here is a my query code that use to always work:
and here is just pulling data in from a table
When program starts, it accesses 3 access 97' databases, 2 of which just pulls information in and 1 of which will record. It wall was working great but suddenly I just keep getting these errors. When I debug it doesn't help much. The only thing I can think of is when I'm pulling or pushing data to/from databases that when the other users are using it, it won't allow multiple user to access it???
After each procedure I set recordset and connection to nothing. Is that correct? Do I need to use a different way to access access when I have multiple users?
here is a my query code that use to always work:
Code:
Sub Pull_Data2()
Dim objRec As Object
Dim lngfield As Long
' Screen updating off
Application.ScreenUpdating = False
'define paths
strDBPath = "G:\Data1\Data2\file.mdb"
Provider = "Provider=Microsoft.Jet.OLEDB.4.0;"
' Selects Sheet and Clears old Values
Sheets("Query").Select
Range("A2:AG100").Clear
'Pull Required Query
strQueryName = Prompt.QueryCBO.Value
On Error Resume Next
Set objRec = RunQuery(strDBPath, strQueryName)
On Error GoTo 0
If Not objRec Is Nothing Then
With Sheets("Query").Range("A2")
For lngfield = 1 To objRec.Fields.Count
.Cells(1, lngfield).Value = objRec.Fields(lngfield - 1).Name
Next lngfield
Call .Offset(1, 0).CopyFromRecordset(objRec)
End With
End If
Set objRec = Nothing
Set Recordset = Nothing
Set Connection = Nothing
and here is just pulling data in from a table
Code:
Sub Pull_Data()
Dim strDBPath As String
Dim Cnct As String, Src As String
Dim Connection As ADODB.Connection
Dim Recordset As ADODB.Recordset
Dim col As Integer
' Screen updating off
Application.ScreenUpdating = False
'define paths
strDBPath = "G:\Data1\Data2\file.mdb"
Provider = "Provider=Microsoft.Jet.OLEDB.4.0;"
' Update Bar
ProgressBar.ProgressLBL.Caption = "Gathering PAR data for Shaft Dept..."
ProgressBar.ProgressLBL2.Caption = strDBPath
ProgressBar.LabelProgress.Width = 5
ProgressBar.FrameProgress.Caption = "5%"
Application.Wait (Now() + CDate("00:00:01"))
' Selects Sheet and Clears old Values
Sheets("PARS").Select
On Error Resume Next
ActiveSheet.ShowAllData
On Error GoTo 0
Range("A:D").Clear
' Create RecordSet
Set Recordset = New ADODB.Recordset
With Recordset
' Filter (SELECT = Field Names FROM = Table WHERE = Citeria)
Src = "SELECT BOM.PARENT, BOM.RUN_LT, BOM.COMPONENT, BOM.QUANTITY" 'Grabs all Field titles
Src = Src & Chr(13) & "" & Chr(10) & "FROM BOM" & Chr(13) & "" & Chr(10) & "WHERE (BOM.COMPONENT='WC[S]15-112-102') OR (BOM.COMPONENT='WC[R]15-112-102')" & _
" OR (BOM.COMPONENT='WC[S]15-112-104') OR (BOM.COMPONENT='WC[R]15-112-104')" & _
" OR (BOM.COMPONENT='WC[S]15-112-120') OR (BOM.COMPONENT='WC[R]15-112-120')" & _
" OR (BOM.COMPONENT='WC[S]15-112-119') OR (BOM.COMPONENT='WC[R]15-112-119')" & _
" OR (BOM.COMPONENT='WC[S]15-112-117') OR (BOM.COMPONENT='WC[R]15-112-117')" & _
" OR (BOM.COMPONENT='WC[S]15-112-116') OR (BOM.COMPONENT='WC[R]15-112-116')" & _
" OR (BOM.COMPONENT='WC[S]15-112-115') OR (BOM.COMPONENT='WC[R]15-112-115')" & _
" OR (BOM.COMPONENT='WC[S]15-112-112') OR (BOM.COMPONENT='WC[R]15-112-112')" & _
" OR (BOM.COMPONENT='WC[S]15-112-113') OR (BOM.COMPONENT='WC[R]15-112-113')" & _
" OR (BOM.COMPONENT='WC[S]15-112-111') OR (BOM.COMPONENT='WC[R]15-112-111')" & _
" OR (BOM.COMPONENT='WC[S]15-112-114') OR (BOM.COMPONENT='WC[R]15-112-114')"
.Open Source:=Src, ActiveConnection:=Provider & _
"Data Source=" & strDBPath & ";" & _
"Jet OLEDB:Engine Type=5;" & _
"Persist Security Info=False;"
' Write the field names
For col = 0 To Recordset.Fields.Count - 1
Range("A1").Offset(0, col).Value = Recordset.Fields(col).Name
Next '
' Write the recordset
Range("A1").Offset(1, 0).CopyFromRecordset Recordset
' Close Access
Set Recordset = Nothing
Set Connection = Nothing
Last edited by a moderator: