473,396 Members | 1,816 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Unable to Pass Form Object to Sub-Type Mismatch

Hello,

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
  1. Private Sub cmdRefresh_Click()
  2. On Error GoTo cmdRefresh_Click_Err
  3. Application.Echo False
  4.     DoCmd.NavigateTo "acNavigationCategoryObjectType", "acNavigationGroupForms"
  5.     DoCmd.RunCommand acCmdWindowHide
  6.     Refresh_User
  7.     DoCmd.OpenForm Me.Name, acNormal, "", "", , acNormal
  8.     Check_Control_Tags_LEV (Forms("Main Menu")) ‘The error happens here
  9.     DoCmd.Maximize
  10.     cmdFocus.SetFocus
  11.     DoCmd.GoToControl "NavigationSubform"
  12.  
  13. cmdRefresh_Click_Exit:
  14. Me.Painting = True
  15. Application.Echo True
  16.     Exit Sub
  17.  
  18. cmdRefresh_Click_Err:
  19.     MsgBox Error$, , "Service Desk Support"
  20.     Resume cmdRefresh_Click_Exit

I get a type mismatch error on the line
Expand|Select|Wrap|Line Numbers
  1. Check_Control_Tags_LEV (Forms("Main Menu"))
This is a public sub found in another module which begins with this code:

Expand|Select|Wrap|Line Numbers
  1. Public Sub Check_Control_Tags_LEV(MyForm As Form)
  2. On Error Resume Next
  3. Dim ctl As Control 
  4. Dim rsControl_Tags As DAO.Recordset2
  5.  
  6. For Each ctl In MyForm.Controls
  7. 'Do other stuff
  8. End Sub
The Check_Control_Tags_LEV sub runs fine on its own, but it's the type mismatch that's killing me, since I can't figure out why it's throwing the error. For example, if I replace the problem line with
Expand|Select|Wrap|Line Numbers
  1. Check_Control_Tags_LEV (Forms("Main Menu").Controls("NavigationSubform").Form)
Then it runs just fine.

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?
Sep 25 '13 #1
3 3146
ADezii
8,834 Expert 8TB
A slightly different approach will do the trick, namely:
Expand|Select|Wrap|Line Numbers
  1. Dim frm As Access.Form
  2. Set frm = Forms("frmTest")
  3.  
  4. Call Check_Control_Tags_LEV(frm)
Expand|Select|Wrap|Line Numbers
  1. Public Sub Check_Control_Tags_LEV(frmForm As Access.Form)
  2. Dim ctl As Control
  3.  
  4. For Each ctl In frmForm.Controls
  5.   Debug.Print ctl.Name
  6. Next
  7. End Sub
Sep 25 '13 #2
For whatever reason, it worked that time. I tried using a Call, and I also tried dimming and Set within the sub, but neither worked the first time around. Odd. Well, it's working now. Thanks!
Sep 26 '13 #3
ADezii
8,834 Expert 8TB
You are quite welcome.
Sep 26 '13 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: Vanessa | last post by:
Hi, I would like to know whether there's any way for me to pass an object by reference to another form? Regards Vanessa
5
by: Simone | last post by:
Hello I am really confused on this. I have a button that calls a module. Sub verifyUser(frmEntry As Form) This module does a few things then it opens a form. I am passing a variable as...
1
by: hrhoe | last post by:
Hi, I'm trying to create a reusable component with C#. So, I created a user control that uses Microsoft SQLDMO Object Library (SQLDMO). And I could add that UserControl on Toolbox. However,...
0
by: Pete Kane | last post by:
Hello All, I'm a seasoned Foxpro programmer who is just feeling the waters of C# using InterOp. Is it possible to pass a Visual Foxpro form object to a ..NET dll method and have the method set some...
3
by: BakelNB | last post by:
I am new to the .Net environment, so please bear with me. I am passing a form object (e.g. formA) to an existing form (e.g. formB) by setting a property value defined in formB to hold the formA...
0
by: pm.thirumalai | last post by:
Hi. I am having problem to get a form object from VB6 to .NET. We are having a dll (ActiveX EXE) which is functioning the common task handing in all of our projects. say, the Dll Contains ...
0
by: hlyall1189 | last post by:
Hi, I recently started upgrading some of my old vs 2003 apps to vs 2005 and used the conversion tool but now i get the following error after building the page. I have typecasted the lines as...
1
by: =?Utf-8?B?RGF2ZQ==?= | last post by:
I have a master page and a content page to that master. When I try to work with them I get an inconsistent error of casting ability and it happens irregularly, which means sometimes it can work...
4
by: rlntemp-gng | last post by:
I have one module where I would like to launch 2 different forms (that do exist), based on a form object and string that is passed into it. (prmTable is a string, not a table object simply because...
6
by: The Frog | last post by:
Hi Guys, Just wanting some opinions on best method to approach this. I am working on an Access97 db and we have two forms and an ADO connection object to contend with. The desired state is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.