Code getting skipped

Huey462

Board Regular
Joined
Jul 25, 2011
Messages
147
I’ve run across a weird problem and I hope someone can shed some light on what is the issue. When the form’s “on current” code is executed, it will count the number of records in each of the subforms that match the user on the main form. This works without any issues. The problem is that some of the code is being skipped (for the lack of a better term).</SPAN>

The count is applied to a global variable</SPAN>
Code:
</SPAN>
  AdminCheck = DCount("MemberSSAN", "qryCurrentAdminDemo", "MemberSSAN='" & Me.txtSSAN & "'")</SPAN>
</SPAN>

After a value is assigned to the variables the code is run for each of the subforms. </SPAN>

Code:
If AdminCheck = "0" Then                    '1  if there are no records</SPAN>
  Me.lblCountAdminDemo.Caption = ""         '2  removes Record X of Y text in label</SPAN>
  Me.btnPrevAdminDemo.Visible = False       '3  makes previous record button invisible</SPAN>
  Me.btnNextAdminDemo.Visible = False       '4  makes next record button invisible</SPAN>
  Me.chkAdminDemo = False                   '5  unchecks box used to see if record exists in queries</SPAN>
  Me.btnAddAdminDemote.Enabled = True       '6  enables button to add record</SPAN>
  Me.btnArchiveAdminDemote.Enabled = False  '7  disables button to archive record (because there isn't one)</SPAN>
  Me.btnDeleteAdminDemote.Enabled = False   '8  disables button to delete record (because there isn't one)</SPAN>
  Else                                      '9  if there are records</SPAN>
  Me.lblCountAdminDemo.Caption = frmAdminDemo.Form.CurrentRecord & " of " & AdminCheck 'updates Record X of Y label</SPAN>
  Me.chkAdminDemo = True                    '10  unchecks box used to see if record exists in queries</SPAN>
  Me.btnAddAdminDemote.Enabled = True       '11  enables button to add record</SPAN>
  Me.btnArchiveAdminDemote.Enabled = True   '12  enables button to archive record</SPAN>
  Me.btnDeleteAdminDemote.Enabled = True    '13  enables button to delete record</SPAN>
    If AdminCheck > 1 Then                  '14  if there is more than one record</SPAN>
    Me.btnPrevAdminDemo.Visible = True      '15  enables previous record button</SPAN>
    Me.btnNextAdminDemo.Visible = True      '16  enables next record button</SPAN>
    Else                                    '17  if there is only one record</SPAN>
    Me.btnPrevAdminDemo.Visible = False     '18  disables previous record button</SPAN>
    Me.btnNextAdminDemo.Visible = False     '19  enables next record button</SPAN>
    End If</SPAN>
  End If</SPAN>

Essentially this same bit of code is used for each subform except for button and other control names that are changed.</SPAN>

Now for the weird part, on the 5th</SPAN> subform, the code stops working. It doesn’t update the checkbox (lines 5 and 10). I’ve copied and pasted the code to a temporary button and when it is ran by itself, it works as advertised. While the code “should” run everything is there a way to force it to slow down and not go to the next bit without getting ahead of itself (for the lack of a better way to explain it)?</SPAN>
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
you could use DoEvents to let it catch up a bit

if you have On Error Resume Next Above this, then it could be stepping out of the code because of a problem

step through the code with F8 to establish where it jumps out
 
Upvote 0
I do have an "On Error Resume Next" because it would pop up an error when the form is initially loaded.<o:p></o:p>
<o:p> </o:p>I'll give the doEvents a try. Thanks
 
Upvote 0

Forum statistics

Threads
1,214,951
Messages
6,122,442
Members
449,083
Latest member
Ava19

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top