Recordset not counting properly when BREAKPOINT not inserted

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
 
M

Michael Banks

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
 
A

Adrian Jansen

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top