Hi,
I'm getting an odd error that I was hoping somebody could shed some light on.
I've got a form, ContactsForm (naming standard is not mine). The first thing this form does in the OnOpen routine is open another form, called ContactsFilterSortForm, as dialog.
The purpose of ContactsFilterSortForm is to set a really, really complicated filter. It does this by getting the criteria, making an SQL statement based on the criteria, then setting a boolean "Selected" field, for all contacts records that fit the criteria, to True. This is done in cmdOK_Click, just before ContactsFilterSortForm closes.
All this works fine. All the contacts form needs to do is open the form, then set the recordsource to show all contacts where "Selected" = True. Or all contacts period, depending on whether a certain drop-down says "Filter" or "All." The drop-down's default value is "Filter."
Here is the code:
Private Sub EvaluateShowFilterAll()
On Error GoTo Err_EvaluateShowFilterAll
Dim strRS As String
Select Case Me.ComboShowWhat
Case "Filter"
strRS = "ContactsQrySelected"
Case "All"
strRS = "ContactsQry"
End Select
SetRS:
Me.RecordSource = strRS
Me.Requery
Exit_EvaluateShowFilterAll:
Exit Sub
Err_EvaluateShowFilterAll:
MsgBox Err.Description, , "EvaluateShowFilterAll: " & Err.Number
Resume Exit_EvaluateShowFilterAll
End Sub
Private Sub Form_Open(Cancel As Integer)
On Error GoTo Err_Form_Open
Dim bolAdminUser As Boolean
'Get filter information from ContactsFilterSortForm
DoCmd.OpenForm "ContactsFilterSortForm", , , , , acDialog
If Not bolProceed Then
'cancel if the user cancelled out of ContactsFilterSort
Cancel = True
DoCmd.OpenForm "frmSwitchboard"
Exit Sub
End If
EvaluateShowFilterAll
'Determine whether the current user is admin.
'Set admin-level tabs to visible or invisible,
'depending on value of (whether user is admin)
bolAdminUser = _
(UCase(GetUserAccessLevelString) = "ADMIN"
Me.Payments.Visible = bolAdminUser
Me.Receivables.Visible = bolAdminUser
Me.Dues.Visible = bolAdminUser
Me.MergeTo.Visible = bolAdminUser
Me.ANA_info.Visible = bolAdminUser
Exit_Form_Open:
Exit Sub
Err_Form_Open:
MsgBox Err.Description, , "Form_Open: " & Err.Number
Resume Exit_Form_Open
End Sub
The red lines are the ones getting the error, "2467: The expression you entered refers to an object that is closed or doesn't exist." The error, and the places it occurs, indicate that ContactsForm is no longer open. When I close the message, the ContactsForm is indeed not open.
If I comment out the entire area in blue, everything runs fine.
bolProceed (a global variable set by ContactsFilterSortForm) = True. So it isn't that.
It also has nothing to do with the GetUserAccessLevelString function (a global function that returns a string indicating user's access level). Again, if I comment out the area in blue, everything works fine.
One odd thing: when troubleshooting, I set a breakpoint on the "EvaluateShowFilterAll" command line. The first thing I saw, before even starting to step through, was the "This action will reset the current code in break mode. Do you want to stop the running code?" dialog box. I usually only see that if I'm stepping through and hit the stop button.
Any insights? I work with dialog forms all the time, and I've never seen anything like this. Katie
I'm getting an odd error that I was hoping somebody could shed some light on.
I've got a form, ContactsForm (naming standard is not mine). The first thing this form does in the OnOpen routine is open another form, called ContactsFilterSortForm, as dialog.
The purpose of ContactsFilterSortForm is to set a really, really complicated filter. It does this by getting the criteria, making an SQL statement based on the criteria, then setting a boolean "Selected" field, for all contacts records that fit the criteria, to True. This is done in cmdOK_Click, just before ContactsFilterSortForm closes.
All this works fine. All the contacts form needs to do is open the form, then set the recordsource to show all contacts where "Selected" = True. Or all contacts period, depending on whether a certain drop-down says "Filter" or "All." The drop-down's default value is "Filter."
Here is the code:
Private Sub EvaluateShowFilterAll()
On Error GoTo Err_EvaluateShowFilterAll
Dim strRS As String
Select Case Me.ComboShowWhat
Case "Filter"
strRS = "ContactsQrySelected"
Case "All"
strRS = "ContactsQry"
End Select
SetRS:
Me.RecordSource = strRS
Me.Requery
Exit_EvaluateShowFilterAll:
Exit Sub
Err_EvaluateShowFilterAll:
MsgBox Err.Description, , "EvaluateShowFilterAll: " & Err.Number
Resume Exit_EvaluateShowFilterAll
End Sub
Private Sub Form_Open(Cancel As Integer)
On Error GoTo Err_Form_Open
Dim bolAdminUser As Boolean
'Get filter information from ContactsFilterSortForm
DoCmd.OpenForm "ContactsFilterSortForm", , , , , acDialog
If Not bolProceed Then
'cancel if the user cancelled out of ContactsFilterSort
Cancel = True
DoCmd.OpenForm "frmSwitchboard"
Exit Sub
End If
EvaluateShowFilterAll
'Determine whether the current user is admin.
'Set admin-level tabs to visible or invisible,
'depending on value of (whether user is admin)
bolAdminUser = _
(UCase(GetUserAccessLevelString) = "ADMIN"
Me.Payments.Visible = bolAdminUser
Me.Receivables.Visible = bolAdminUser
Me.Dues.Visible = bolAdminUser
Me.MergeTo.Visible = bolAdminUser
Me.ANA_info.Visible = bolAdminUser
Exit_Form_Open:
Exit Sub
Err_Form_Open:
MsgBox Err.Description, , "Form_Open: " & Err.Number
Resume Exit_Form_Open
End Sub
The red lines are the ones getting the error, "2467: The expression you entered refers to an object that is closed or doesn't exist." The error, and the places it occurs, indicate that ContactsForm is no longer open. When I close the message, the ContactsForm is indeed not open.
If I comment out the entire area in blue, everything runs fine.
bolProceed (a global variable set by ContactsFilterSortForm) = True. So it isn't that.
It also has nothing to do with the GetUserAccessLevelString function (a global function that returns a string indicating user's access level). Again, if I comment out the area in blue, everything works fine.
One odd thing: when troubleshooting, I set a breakpoint on the "EvaluateShowFilterAll" command line. The first thing I saw, before even starting to step through, was the "This action will reset the current code in break mode. Do you want to stop the running code?" dialog box. I usually only see that if I'm stepping through and hit the stop button.
Any insights? I work with dialog forms all the time, and I've never seen anything like this. Katie