J
JM
I loaded some windows updates to my PC today, which included a Jet 4 patch.
Since then I've had a problem. If I run some code, then the database becomes
locked, even to me.
In other words suppose I edit my code. Before testing the changes, I can
save the module. After running I cannot, the db is locked. I am warned that
"You do not have exclusive access to the database at this time. Your changes
will not be saved". However it is only opened by me.
More importantly I can't see any db objects that I've left open. It seems to
be the With Currentdb that "opens" the db, but that's a bog standard line.
The following code is the one I'm trying to edit.
I am running Access 200 Win XP Home and references Jet DAO 3.6
Sub test_SetChurn()
Dim sDB As String, db As DAO.Database
'Get path for Results db
sDB = GetSetting(scAppTitle, "Parameters", "AccessDB01", "")
If sDB = "" Then MsgBox "Error, no Data db located", vbCritical, "Error":
Exit Sub
Set db = OpenDatabase(sDB)
fnSetChurnLife 4, db
db.Close
Set db = Nothing
End Sub
Public Function fnSetChurnLife(iOption As Integer, db As DAO.Database) As
Boolean
'Purpose: This prodecure sets the Life column in a table dealing with
Churn
'Parameters: dAvgChurn - This is the calculated churn taken from the
given period figures
' dExpectedChurn - This is the predicted churn. It is stored
in tbParameters. The above figure in theory should match this
' dMaximumLife - This is the maximum life. It is stored in
tbParameters. The parameter is design to prevent excessive Life predictions
'--------------------------------------------------------------------
Dim dAvgChurn(1) As Double, dExpectedChurn(1) As Double, dMaximumLife(1)
As Double, sCurrentPeriod As String
Dim sSQL As String, sSQL_Insert As String, sSQL_Select As String,
sSQL_From As String
Dim sTable As String, i As Integer 'arrSQL As Variant
Const sChurnLifeTable As String = "dtChurnRate"
Dim rst As DAO.Recordset
sTable = "dtDimTable"
On Error GoTo errFunction
With CurrentDb
'1. Get current period
sCurrentPeriod = GetSetting(scAppTitle, "Parameters", "CurrentPeriod",
"2003-01")
'2. Get calculated churn figures.
' Calculated Churn is the actual value from the period's figures
sSQL = "SELECT IIf([CustomerTypeOros]='Prepaid','Prepaid','Postpaid') AS
Type, " _
& "Sum(tbDataChurn.Subscribers) AS Subscribers, " _
& "Sum(IIf([tbDataChurn].[IsChurn],[tbDataChurn].[Subscribers],0)) AS
SubIsChurn " _
& "FROM tbDataChurn LEFT JOIN tbLookupCustomerType ON
tbDataChurn.CustomerType = tbLookupCustomerType.CustomerTypeSource " _
& "WHERE (((tbDataChurn.Period) = '" & sCurrentPeriod & "')) " _
& "GROUP BY IIf([CustomerTypeOros]='Prepaid','Prepaid','Postpaid') " _
& "ORDER BY IIf([CustomerTypeOros]='Prepaid','Prepaid','Postpaid');"
Set rst = .OpenRecordset(sSQL, dbOpenForwardOnly)
'2.1 Postpaid
dAvgChurn(notPPD) = rst(2) / rst(1)
'2.2 Prepaid
rst.MoveNext
dAvgChurn(PPD) = rst(2) / rst(1)
rst.Close
'code snipped out here because to isolate this problem I commented it all
out but it still generates the error.
fnSetChurnLife = True
exitFunction:
Set rst = Nothing
' CurrentDb.Close
Exit Function
errFunction:
Select Case Err
Case Else
MsgBox Err.Description & " (" & Err & ")", vbCritical, "Error"
End Select
End With
fnSetChurnLife = False
Resume exitFunction
End Function
Since then I've had a problem. If I run some code, then the database becomes
locked, even to me.
In other words suppose I edit my code. Before testing the changes, I can
save the module. After running I cannot, the db is locked. I am warned that
"You do not have exclusive access to the database at this time. Your changes
will not be saved". However it is only opened by me.
More importantly I can't see any db objects that I've left open. It seems to
be the With Currentdb that "opens" the db, but that's a bog standard line.
The following code is the one I'm trying to edit.
I am running Access 200 Win XP Home and references Jet DAO 3.6
Sub test_SetChurn()
Dim sDB As String, db As DAO.Database
'Get path for Results db
sDB = GetSetting(scAppTitle, "Parameters", "AccessDB01", "")
If sDB = "" Then MsgBox "Error, no Data db located", vbCritical, "Error":
Exit Sub
Set db = OpenDatabase(sDB)
fnSetChurnLife 4, db
db.Close
Set db = Nothing
End Sub
Public Function fnSetChurnLife(iOption As Integer, db As DAO.Database) As
Boolean
'Purpose: This prodecure sets the Life column in a table dealing with
Churn
'Parameters: dAvgChurn - This is the calculated churn taken from the
given period figures
' dExpectedChurn - This is the predicted churn. It is stored
in tbParameters. The above figure in theory should match this
' dMaximumLife - This is the maximum life. It is stored in
tbParameters. The parameter is design to prevent excessive Life predictions
'--------------------------------------------------------------------
Dim dAvgChurn(1) As Double, dExpectedChurn(1) As Double, dMaximumLife(1)
As Double, sCurrentPeriod As String
Dim sSQL As String, sSQL_Insert As String, sSQL_Select As String,
sSQL_From As String
Dim sTable As String, i As Integer 'arrSQL As Variant
Const sChurnLifeTable As String = "dtChurnRate"
Dim rst As DAO.Recordset
sTable = "dtDimTable"
On Error GoTo errFunction
With CurrentDb
'1. Get current period
sCurrentPeriod = GetSetting(scAppTitle, "Parameters", "CurrentPeriod",
"2003-01")
'2. Get calculated churn figures.
' Calculated Churn is the actual value from the period's figures
sSQL = "SELECT IIf([CustomerTypeOros]='Prepaid','Prepaid','Postpaid') AS
Type, " _
& "Sum(tbDataChurn.Subscribers) AS Subscribers, " _
& "Sum(IIf([tbDataChurn].[IsChurn],[tbDataChurn].[Subscribers],0)) AS
SubIsChurn " _
& "FROM tbDataChurn LEFT JOIN tbLookupCustomerType ON
tbDataChurn.CustomerType = tbLookupCustomerType.CustomerTypeSource " _
& "WHERE (((tbDataChurn.Period) = '" & sCurrentPeriod & "')) " _
& "GROUP BY IIf([CustomerTypeOros]='Prepaid','Prepaid','Postpaid') " _
& "ORDER BY IIf([CustomerTypeOros]='Prepaid','Prepaid','Postpaid');"
Set rst = .OpenRecordset(sSQL, dbOpenForwardOnly)
'2.1 Postpaid
dAvgChurn(notPPD) = rst(2) / rst(1)
'2.2 Prepaid
rst.MoveNext
dAvgChurn(PPD) = rst(2) / rst(1)
rst.Close
'code snipped out here because to isolate this problem I commented it all
out but it still generates the error.
fnSetChurnLife = True
exitFunction:
Set rst = Nothing
' CurrentDb.Close
Exit Function
errFunction:
Select Case Err
Case Else
MsgBox Err.Description & " (" & Err & ")", vbCritical, "Error"
End Select
End With
fnSetChurnLife = False
Resume exitFunction
End Function