I have created a subroutine that is declared as public in one of my form modules. In another form module I am trying to call it. However, when I try to compile my code, I get an error that says Sub or Function not defined.
I'm calling it like this:
And it is declared like this: - Public Sub InOutStatus()
-
-
End Sub
When I actually run the code, it works fine. Why am I getting a compiler error?
Note: By form module, I mean the object that gets created in the Microsoft Access Class Objects group in the VBA editor whenever you create an event in the form. I'm not exactly sure what to call it, so I chose form module.
Form Modules, while visible to all code, are not General Modules, so need qualification when referred to. The code should read : - Call Form_frmYourForm.InOutStatus
or (only if the form is open) : - Call Forms("frmYourForm").InOutStatus
Alternatively, it is very unusual for code from a specific form to be called from outside of that form. It normally (Though not necessarily) indicates the procedure is in the wrong place.
10 1399 NeoPa 32,556
Expert Mod 16PB
Form Modules, while visible to all code, are not General Modules, so need qualification when referred to. The code should read : - Call Form_frmYourForm.InOutStatus
or (only if the form is open) : - Call Forms("frmYourForm").InOutStatus
Alternatively, it is very unusual for code from a specific form to be called from outside of that form. It normally (Though not necessarily) indicates the procedure is in the wrong place.
That did it. Even though during normal use the called form will be open, I went ahead and used your first option so that if I ever need to do some troubleshooting on the calling form, I don't have to worry about making sure another form is open.
Thanks NeoPa!
Just some useless information. A Sub-Routine defined within a Form's Class Module is essentially a Method of that Form, ergo the
Calling Syntax.
I wouldn't call that useless information. It helps it make sense to me of why. Thanks ADezii.
NeoPa 32,556
Expert Mod 16PB
I agree Seth. It's not remotely useless :-)
Oh, and BTW you're welcome to the assistance.
NeoPa 32,556
Expert Mod 16PB
I forgot to mention earlier that there is another strange issue that comes up every now and again where the compiler seems to get its knickers in a twist and complains about something not being there, when clearly it is. I've found that by cutting the declaration code out, then pasting it back in again, the compiler seems to come to its senses and again recognise that it actually exists. Don't worry about this if your issue is already fixed, but for any others reading this thread where nothing else has worked, this simple fix is always worth a try.
If your code is acting "weird" (yes that really is the best word I could come up with) then I have found its often a matter of in-consistent compilation, the cause of which is usually editing "live/running" code. Don't ever do that!
I have found it often helps to decompile the application: http://bytes.com/topic/access/insigh...-fresh-compile
Note that forms are a class, and that YOUR form is a sub-class of forms. Thats why you can use the following: - Dim frm as Form_YOURFORMNAME
-
Set frm=Forms("Form_YOURFORMNAME") 'Only works if open
Now you might wonder what the benefit of this would be. The clear benefit is that you actually get intellisense of the controls in the form. Just like you can do Me. to show (among others) controls in your form, you can also now do frm. .
NeoPa 32,556
Expert Mod 16PB Smiley:
Don't ever do that!
Indeed. I appreciate the potential problems involved. I actually do do it regularly myself, but I have procedures I follow which ensure this problem doesn't occur with me any more (At least I can't remember it happening for ages and ages so I assume they're reliable). Nevertheless, I have kept up with the linked thread and, in general, would advise members similarly (to your quoted comment that is. Avoid it like the plague).
Nevertheless, I still remember it happening and I can't assume that everyone has avoided the problem just because we have Smiley, hence the idea to post my quick fix (which essentially flags the code as not compiled, just as a specific decompilation would). Smiley: - Dim frm as Form_YOURFORMNAME
-
Set frm=Forms("Form_YOURFORMNAME") 'Only works if open
I found, in A2003, that it could be run, and does work, whether the form is open or otherwise. However, it causes the form to stay loaded (if not necessarily open) if an attempt is made to close it while your code still has any active references to it. Similarly, it will cause the object to be loaded if your code runs at a time when it is not already loaded.
In most cases this will not be an issue, but I have fallen over it myself when dealing with all the forms in a database with (literally) hundreds of them to process through. My process crashed complaining of lack of resources, as I recall. Tidier code was required once I appreciated what was happening.
Anyway, I digress. I just wanted to add the Government Health Warning (that I should have added earlier when I first introduced the idea into the thread.), in case anyone saw it and decided to use it more extensively.
BTW Smiley's point about all forms and reports being classes in their own right, which are simply derived classes from the main classes Form and Report that all Access databases have, is absolutely right and can be an important point to be aware of.
I will admit to doing it myself once in a while (Editing live code) but I do try to steer clear of it, since I know and realise the potential issues involved. It sometimes feels like that "game" boys played as kids, who could hold their hand over the flame the longest without getting burnt. Its fun and games, but well, every once in a while somebody got burnt!
The decompilation however will affect all modules, where your fix only affects a single module at a time.
Also remember that you can safely modify values during breakmode, by using the immediate pane. That can be quite usefull, to more quickly try out different scenarios.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: paul calvert |
last post by:
I hope somewhere here has encountered and solved a similar problem in
the past.
1) on a new Win2000 PC:
installed Visual C++ 6.0
download & install single file Service Pack 5.0
2) try to...
|
by: EmmanuelE |
last post by:
Just installed VS2003 and tried a hello world app. Getting 404 error even
when I explictly specify the start page in the url.
In IIS Mgr (v 5.1), App has .aspx mapped to...
|
by: jt |
last post by:
I'm getting a compiler error: warning C4172: returning address of local
variable or temporary
Here is the function that I have giving this error: I'm returning a
temporary char string and its...
|
by: ravi.sathyam |
last post by:
Hi,
so basically I define a struct as follows:
struct speechSegment {
float coeff_Array;
float period;
float energy;
};
struct speechSegment segment = { /*I fill this struct with info */};
|
by: Richard |
last post by:
Hi All,
I am using Visual C++ .Net to create a windows forms application and I am
getting the following errors when I do a MessageBox::Show in my Form1.cpp
file:
Form1.cpp(19): error C2653:...
|
by: Jay |
last post by:
Hi,
I have been working on ASP.NET 2.0. When I was trying to work with one of
the master pages, I used some classes (.vb files) in App_code directory. When
the application is run, it gives me the...
|
by: erik.erikson |
last post by:
I am getting a compiler error that I can't well explain or even
understand the origin of (though I boiled it down close...). Below is
a bare-bones example.
What I am doing is defining the...
|
by: gmsieling |
last post by:
We're getting compiler error CS0006, with increasing frequency. It says that a randomly named DLL was not found. This happens at random intervals when you try to run the application. We're using the...
|
by: Yahooooooooo |
last post by:
Hi,
whats the issue in below code ...
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <iterator>
#include <boost/regex.hpp>
|
by: ayan4u |
last post by:
HBITMAP patternBMP =NULL;
patternBMP = (HBITMAP)LoadImge(hInstance, "bitmap.bmp", IMAGE_BITMAP,0,0,LR_LOADFROFILE);
getting a compiler error
error C2664: 'LoadImageW' : cannot convert...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
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...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |