473,378 Members | 1,395 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,378 software developers and data experts.

Module Compiling Issues

I have code that needs to be used in multiple events. Please see link:

https://bytes.com/topic/access/answe...nt-not-working

I am having trouble with a Compile Error when I try to run it. Here is what I did, I placed it in a Module saved the Module as My_enableDisable. Then created the Private sub using the code. I called it in each event AfterUpdate and OnCurrent.
When I do this an error comes up.

what the Error says:

Compile Error!
Expected variable or procedure not module.

I am not certain how to do this. Can you give me some advice and share some good links to go learn more on How to better understand using Modules?

Thank you!
Sep 10 '16 #1

✓ answered by PhilOfWalton

Is the Sub EnableDisable in the same module that you are calling it from (Sorry about the preposition at the end of the sentence).

If not, try removing the word Private

Phil

9 997
PhilOfWalton
1,430 Expert 1GB
Usually caused by the name of a function or sub in ANY module having the same name as a module.

I believe you have a Sub called EnableDisable. Might be worth changing the module name.

Phil
Sep 10 '16 #2
I recognized I inadvertently named them the same and changed the Module name to My_enableDisable. When I tried it again, I still got an error. It said,

Compile Error
Sub or Function not defined

What am I missing?

Thanks
Sep 12 '16 #3
PhilOfWalton
1,430 Expert 1GB
Have you got
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
at the head of EVERY Module in your database?

Phil
Sep 12 '16 #4
Phil

I do.

I have the Module set as a private sub thinking it only needs to work in this database and it is a sub not a function.

I tried calling it 2 different ways in the form and got the same error:
The first way:

call enableDisable

The second way:

enableDisable


Katc Dolly
Sep 12 '16 #5
PhilOfWalton
1,430 Expert 1GB
Is the Sub EnableDisable in the same module that you are calling it from (Sorry about the preposition at the end of the sentence).

If not, try removing the word Private

Phil
Sep 12 '16 #6
Phil,
I removed the Private. Then a new compile error appeared highlighting the Me. I replaced the Me with Forms!FormName! in each Me. After that, It worked!! :)

I understand why Me needed to be replaced, but what did the Private do?

Do you have a recommendation to read and learn more about Modules?

Thank you for your help
Sep 13 '16 #7
PhilOfWalton
1,430 Expert 1GB
Not easy to explain, bu I'll have a go. I hope some of the other contributers will add to the explanation.

All functions in Form & Report modules are by definition Private, because they are only accessible from that form or report.

All Functions in normal Modules are Public unless preceded by the word "Private".

So a Function or Sub in a Form or Report can call a (Public) Function or Sub in a normal module. That (Public) function can call a Private Function or Sub, but only if it is in the same module.

So if you have a number of normal modules, they can have Private Functions and Subs with the same names that do different things, but if they are Public Functions or Subs, they need different names, otherwise Access wouldn't know which one to use.

Hope that helps a bit.

As for reading matter, I have no idea. If I get stuck I usually find what I want using Google or "Bytes"

Phil
Sep 13 '16 #8
jforbes
1,107 Expert 1GB
Phil nailed it, but this is here and might be helpful: Variable Scope in VBA for MS Access
Sep 13 '16 #9
Phil and jforbes,

Thank you! T

The explanation and added reading are very educational and helpful. I will be back with more questions as I process this information. Thanks for your wisdom and support.
Sep 13 '16 #10

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

Similar topics

0
by: Aliencat | last post by:
I'm having issues compiling php v4.2.2 on Redhat 9.0. The goal ultimately is to compile in mcrypt support, but that's a bit down the road from here. I've chased down the dependencies for the...
5
by: Mike S. | last post by:
Hello, Has anyone had success compiling the informixdb-1.3 module under python 2.2? It seems the absense of makefile.pre.in in python 2.2 causes the break under py2.2. Is there an easy way...
0
by: F. GEIGER | last post by:
py2exe and datetime -> No module named datetime I've begun to use the stdlib module datetime instead of my home brewn classes. Since then a py2exe app doesn't run anymore: Traceback (most...
0
by: Brandon Craig Rhodes | last post by:
Python modules written in C are often written as single .c files (sometimes quite large) so that everything can be declared "static" except for the init<module>() function; and though the Extending...
0
by: A. B., Khalid | last post by:
Hello all. After the effort of getting most of Python 2.3.4 Final compiled in MinGW (see: http://mail.python.org/pipermail/python-list/2004-June/225967.html, and get the patch and read more...
0
by: David W. Fenton | last post by:
Today I was working on a hideous old app that I created a long time ago that does a lot of showing/hiding/resizing of fields on one of the forms. I had used constants to store reference values for...
22
by: goutham1 | last post by:
hai mate any body plese help me how to run the programme after it is compiled.after pressing ctrl f9 a screen should appear to assagin the values for what we have written.so that it give us answer....
1
by: Kevin T. Ryan | last post by:
Hi All - I'm trying to compile Python on a Centos machine (RHEL) 3.8 for a hosting account that I just set up and I'm having 2 issues: 1. I ran into an issue with the "hashlib" module ...
3
by: davemerkel | last post by:
Hi folks - wondering if anyone has any pointers on troubleshooting garbage collection. My colleagues and I are running into an interesting problem: Intermittently, we get into a situation where...
22
by: ben mitch | last post by:
Hi I hope you'll see this cross-post (c/c++) as appropriate. I also admit immediately that the question *may* turn out to be compiler-/os-specific, in which case I apologize. But I wonder if...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.