Within my VBA code I was attempting to input some error handling, but I'm getting a looping effect I can't get out of without Ctrl-Alt-Del and killing the process. I also am unable to determine what the error is that's occuring, so therefore, am unable to repair. Here's the VBA sub in question:
The intent of this Sub is to look at a hidden, unbound textbox on the form that contains the username of the current environment. I placed in the OnActivate option because I'm not sure at what point this textbox is filled and validated. Should I be placing my code in the OnCurrent instead?
The username in the box is then checked against a table of administrative users, and if the username exists in the table, then certain command buttons are made visible, otherwise they're hidden. There's also a special control button which I want visible for just myself to let me see who is currently using the database in case I need to send them a message to exit if they've been in all day and I need to make changes to tables/forms etc.
If I remove the error handling, then the form opens fine, but I'm trying to figure out why it might be calling the error handler at all if there isn't an error occurring. Even if I just remove the "Resume" line it will give me the error #0 msgbox, but continue to open. with the code as shown I get the first message box which says "Error #0" and no data, and then another msgbox opens saying "Error #20" "Resume without Error" and goes into a continuous loop. All other subs which use error handling have a resume command like this and they will exit the sub as they're supposed to do upon an error.
Kyle
Code:
Private Sub Form_Activate()
On Error GoTo Exit_Form_Activate
If DCount("[Allowed Usernames]", "[tbl Database Admins]", _
"[Allowed Usernames] = '" & Environ("username") & "'") = 1 Then
Me.Modify_Budget.Visible = True
Me.Modify_Forecast.Visible = True
Me.Modify_Calculation_Factors.Visible = True
Me.Daily_Data_Entry.Visible = True
Me.Email_Report.Visible = True
Me.Email_Report_Text.Visible = True
Me.Modify_Email_List.Visible = True
Me.Database_Admin_List.Visible = True
Else
Me.Modify_Budget.Visible = False
Me.Modify_Forecast.Visible = False
Me.Modify_Calculation_Factors.Visible = False
Me.Daily_Data_Entry.Visible = False
Me.Email_Report.Visible = False
Me.Email_Report_Text.Visible = False
Me.Modify_Email_List.Visible = False
Me.Database_Admin_List.Visible = False
End If
If (Me.UserNameControl__UserNameControl = "kbeebe") Then
Me.Find_Who_s_On.Visible = True
Me.Who_s_in_the_Database_.Visible = True
Else
Me.Find_Who_s_On.Visible = False
Me.Who_s_in_the_Database_.Visible = False
End If
Exit_Form_Activate:
MsgBox Err.Description, vbExclamation, "Error #" & Err.Number
Resume Exit_Form_Activate
Exit Sub
End Sub
The intent of this Sub is to look at a hidden, unbound textbox on the form that contains the username of the current environment. I placed in the OnActivate option because I'm not sure at what point this textbox is filled and validated. Should I be placing my code in the OnCurrent instead?
The username in the box is then checked against a table of administrative users, and if the username exists in the table, then certain command buttons are made visible, otherwise they're hidden. There's also a special control button which I want visible for just myself to let me see who is currently using the database in case I need to send them a message to exit if they've been in all day and I need to make changes to tables/forms etc.
If I remove the error handling, then the form opens fine, but I'm trying to figure out why it might be calling the error handler at all if there isn't an error occurring. Even if I just remove the "Resume" line it will give me the error #0 msgbox, but continue to open. with the code as shown I get the first message box which says "Error #0" and no data, and then another msgbox opens saying "Error #20" "Resume without Error" and goes into a continuous loop. All other subs which use error handling have a resume command like this and they will exit the sub as they're supposed to do upon an error.
Kyle