I keep receiving a Type mismatch error when trying to pass a Form object to a subroutine in another module.
I have a navigation form called Main Menu with a subform control called NavigationSubform. On the Main Menu form I have a refresh button cmdRefresh that runs some code to refresh the menu. Here is the code from the Main Menu form’s module:
Expand|Select|Wrap|Line Numbers
- Private Sub cmdRefresh_Click()
- On Error GoTo cmdRefresh_Click_Err
- Application.Echo False
- DoCmd.NavigateTo "acNavigationCategoryObjectType", "acNavigationGroupForms"
- DoCmd.RunCommand acCmdWindowHide
- Refresh_User
- DoCmd.OpenForm Me.Name, acNormal, "", "", , acNormal
- Check_Control_Tags_LEV (Forms("Main Menu")) ‘The error happens here
- DoCmd.Maximize
- cmdFocus.SetFocus
- DoCmd.GoToControl "NavigationSubform"
- cmdRefresh_Click_Exit:
- Me.Painting = True
- Application.Echo True
- Exit Sub
- cmdRefresh_Click_Err:
- MsgBox Error$, , "Service Desk Support"
- Resume cmdRefresh_Click_Exit
I get a type mismatch error on the line
Expand|Select|Wrap|Line Numbers
- Check_Control_Tags_LEV (Forms("Main Menu"))
Expand|Select|Wrap|Line Numbers
- Public Sub Check_Control_Tags_LEV(MyForm As Form)
- On Error Resume Next
- Dim ctl As Control
- Dim rsControl_Tags As DAO.Recordset2
- For Each ctl In MyForm.Controls
- 'Do other stuff
- End Sub
Expand|Select|Wrap|Line Numbers
- Check_Control_Tags_LEV (Forms("Main Menu").Controls("NavigationSubform").Form)
I’ve tried using Forms(Me.Name), Forms![Main Menu], dimming a Form object and using Set, etc., but none of them work. Surely I’m missing something. Though it’s odd the code runs without errors when I do the subform, but not the main form. Any thoughts?