G
Guest
Can someone please look at my code and help me determine why it won't work?
I have been working on this for so long and made several changes to it, I'm
ready to tear my hair out. Originally, it was pulling only the first record
and then it was adding the first record so many times that I got an overflow
error. Now it is bombing out completely. Not knowing which database it is
referring to, I checked to see if anyone was in the remote database and they
were not.
Please help if you can!
Arlene
Error message:
Please record this information: Cannot start your application. The
workgroup information file is missing or opened exclusively by another user.
–2147217843 Microsoft JET Database Engine.
My Code:
Public Sub GetVocalIncidents()
On Error GoTo ErrHandler
Dim cnn As ADODB.Connection
Dim rst As ADODB.Recordset
Dim strSQL As String, strConnection As String
Dim TargetRS As Recordset
Set cnn = New ADODB.Connection
Dim fOpenedCnn As Boolean
Dim fOpenedRst As Boolean
Dim fOpenedTargetRS As Boolean
strSQL = "SELECT * FROM MyTable;"
strConnection = ""
cnn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;
Password=MyPassword;User ID=MyUserID; Data Source=MyDataSourcePath; Persist
Security Info=True; Jet OLEDB:System database=MySystemDB"
cnn.Open adOpenDynamic, adLockReadOnly
fOpenedCnn = True
Set rst = New ADODB.Recordset
With rst
.ActiveConnection = cnn
.Source = strSQL
.Open
fOpenedRst = True
End With
'Do something here
Set TargetRS = CurrentDb.OpenRecordset("TargetRecordset")
fOpenedTargetRS = True
With TargetRS
Do Until .EOF
Dim i As Integer
For i = 0 To .RecordCount - 1
.AddNew
TargetRS.Fields("Field 1") = rst.Fields("Field 1")
.Update
Next i
.MoveNext
Loop
.Close
End With
rst.Close
cnn.Close
Exit Sub
CleanUp:
If (fOpenedRst) Then
rst.Close
fOpenedRst = False
End If
If (fOpenedTargetRS) Then
TargetRS.Close
fOpenedTargetRS = False
End If
If (fOpenedCnn) Then
cnn.Close
fOpenedCnn = False
End If
Set rst = Nothing
Set TargetRS = Nothing
Set cnn = Nothing
Exit Sub
ErrHandler:
MsgBox "Please record this information: " & Err.Description & " " &
Err.Number & " " & Err.Source, vbOKOnly, "Error"
Err.Clear
GoTo CleanUp
End Sub
I have been working on this for so long and made several changes to it, I'm
ready to tear my hair out. Originally, it was pulling only the first record
and then it was adding the first record so many times that I got an overflow
error. Now it is bombing out completely. Not knowing which database it is
referring to, I checked to see if anyone was in the remote database and they
were not.
Please help if you can!
Arlene
Error message:
Please record this information: Cannot start your application. The
workgroup information file is missing or opened exclusively by another user.
–2147217843 Microsoft JET Database Engine.
My Code:
Public Sub GetVocalIncidents()
On Error GoTo ErrHandler
Dim cnn As ADODB.Connection
Dim rst As ADODB.Recordset
Dim strSQL As String, strConnection As String
Dim TargetRS As Recordset
Set cnn = New ADODB.Connection
Dim fOpenedCnn As Boolean
Dim fOpenedRst As Boolean
Dim fOpenedTargetRS As Boolean
strSQL = "SELECT * FROM MyTable;"
strConnection = ""
cnn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;
Password=MyPassword;User ID=MyUserID; Data Source=MyDataSourcePath; Persist
Security Info=True; Jet OLEDB:System database=MySystemDB"
cnn.Open adOpenDynamic, adLockReadOnly
fOpenedCnn = True
Set rst = New ADODB.Recordset
With rst
.ActiveConnection = cnn
.Source = strSQL
.Open
fOpenedRst = True
End With
'Do something here
Set TargetRS = CurrentDb.OpenRecordset("TargetRecordset")
fOpenedTargetRS = True
With TargetRS
Do Until .EOF
Dim i As Integer
For i = 0 To .RecordCount - 1
.AddNew
TargetRS.Fields("Field 1") = rst.Fields("Field 1")
.Update
Next i
.MoveNext
Loop
.Close
End With
rst.Close
cnn.Close
Exit Sub
CleanUp:
If (fOpenedRst) Then
rst.Close
fOpenedRst = False
End If
If (fOpenedTargetRS) Then
TargetRS.Close
fOpenedTargetRS = False
End If
If (fOpenedCnn) Then
cnn.Close
fOpenedCnn = False
End If
Set rst = Nothing
Set TargetRS = Nothing
Set cnn = Nothing
Exit Sub
ErrHandler:
MsgBox "Please record this information: " & Err.Description & " " &
Err.Number & " " & Err.Source, vbOKOnly, "Error"
Err.Clear
GoTo CleanUp
End Sub