As I vaguely recall there was a bug in earlier versions involving
the use of booleans in VBA modules that could cause a problem. If
my memory serves me right it had something to do with code like
the following
'===== This could cause the database to remain open ====
Dim tfBool as Boolean
If TfBool Then
do x
else
do y
End IF
I think that Boolean variables were not the cause of the problem,
but getting Boolean values from controls, such a checkboxes.
Thus:
If Me!chkCheckBox Then
....should be changed to:
If (Me!chkCheckBox) Then
....or:
If Me!chkCheckBox = True Then
The first version causes implicit references that don't get
resolved, while the alternatives force evaluation of the value in
the checkbox control so there is no implicit reference to the
control.
BTW, in regard to implicit references, I believe I recently resolved
an ongoing problem that I'd had with concatenating memo fields. What
I found was this:
Public Function ConcMemos(varMemo1 As Variant, _
varMemo2 As Variant) As Variant
ConcMemos = varMemo1 & varMemo2
End Function
....when the passed in values were fields from a recordset would
result sometimes (but not always) in the return value being
truncated around 255 characters, even when the sum of the lengths of
the passed-in values was greater than 255 characters.
I believe I've solved this with this:
Public Function ConcMemos(ByVal varMemo1 As Variant, _
ByVal varMemo2 As Variant) As Variant
ConcMemos = varMemo1 & varMemo2
End Function
When called like this:
Dim rs As DAO.Recordset
Dim strOutput As String
Set rs = CurrentDB.OpenRecordset("SELECT * FROM tblInventory")
If rs.Recordcount > 0 Then
rs.MoveFirst
Do Until rs.EOF
strOutput = ConcMemos(rs!Memo1, rs!Memo2)
Debug.Print strOutput
Loop
End If
....without the ByVal (i.e., implicit ByRef), the truncation occurs,
and when using ByVal, it does not.
Apparently, with the implicit ByRef there were too many chained
references and the data buffers were just not getting properly
allocated.
This is a problem I've been struggling with for almost 10 years!
It's made me decide to use ByRef only when I know I need it.