Recordset not counting properly when BREAKPOINT not inserted

  • Thread starter Thread starter Michael Banks
  • Start date Start date
M

Michael Banks

I have some code that displays a subform based on the recordset
available.

The code counts up the recordset and if it is greater than 1, displays
the subform. Problem is that this only happens when I insert a
Breakpoint at the start of the code. If the breakpoint is not in place
then the code doesn't perform correctly.

Here is the code:

Dim EquipmentCount As Integer
EquipmentCount = 0
EquipmentCount =
Forms!frmtransformers![subfrmTransformers].Form.RecordsetClone.RecordCount
'Not counting this properly
Debug.Print "EquipmentCount is " & EquipmentCount
If EquipmentCount > 0 Then
Forms!frmtransformers!subfrmTransformers.Form.Visible = True
Else
Forms!frmtransformers!subfrmTransformers.Form.Visible = False
End If
Debug.Print "Transformers at " & Forms!frmtransformers!cboService_Center
& " " & Forms!frmtransformers!cboSubstation_Name & " is " &
Forms!frmtransformers!subfrmTransformers.Form!.RecordsetClone.RecordCount

EquipmentCount = 0

I am resetting the EquipmentCount before and after the code is ran, that
doesn't seem to help me though.

If I put in a Breakpoint at the line EquipmentCount = 0 then the code
works correctly, i.e. my debug.prints would be:

EquipmentCount is 4
Transformers at SBY ADAMS is 4
And the subform is visible.

If I don't have a breakpoint insterted then I get:

EquipmentCount is 0
Transformers at SBY ADAMS is 0
And the subform isn't visible.

I am confused as to why this happens. Please offer up opinions.
Thanks
Mike
 
I was able to determine my own error. The subfrm was set not visible
initially and therefore was working fine just invisible. Sorry about
that.

Thanks though
Mike
 
While the visible property might do this, you may still get problems with
the recordcount. Best seems to be to do a Movelast on the recordset, then
you know all records are loaded before you do the recordcount.

--
Regards,

Adrian Jansen
J & K MicroSystems
Microcomputer solutions for industrial control
Michael Banks said:
I was able to determine my own error. The subfrm was set not visible
initially and therefore was working fine just invisible. Sorry about
that.

Thanks though
Mike

Michael said:
I have some code that displays a subform based on the recordset
available.

The code counts up the recordset and if it is greater than 1, displays
the subform. Problem is that this only happens when I insert a
Breakpoint at the start of the code. If the breakpoint is not in
place then the code doesn't perform correctly.

Here is the code:

Dim EquipmentCount As Integer
EquipmentCount = 0
EquipmentCount =
Forms!frmtransformers![subfrmTransformers].Form.RecordsetClone.RecordCount
'Not counting this properly
Debug.Print "EquipmentCount is " & EquipmentCount
If EquipmentCount > 0 Then
Forms!frmtransformers!subfrmTransformers.Form.Visible = True
Else
Forms!frmtransformers!subfrmTransformers.Form.Visible = False
End If
Debug.Print "Transformers at " &
Forms!frmtransformers!cboService_Center & " " &
Forms!frmtransformers!cboSubstation_Name & " is " &
Forms!frmtransformers!subfrmTransformers.Form!.RecordsetClone.RecordCount

EquipmentCount = 0

I am resetting the EquipmentCount before and after the code is ran,
that doesn't seem to help me though.

If I put in a Breakpoint at the line EquipmentCount = 0 then the code
works correctly, i.e. my debug.prints would be:

EquipmentCount is 4
Transformers at SBY ADAMS is 4
And the subform is visible.

If I don't have a breakpoint insterted then I get:

EquipmentCount is 0
Transformers at SBY ADAMS is 0
And the subform isn't visible.

I am confused as to why this happens. Please offer up opinions.
Thanks
Mike
 
Back
Top