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

Public sub

59
I have a bigger question but lets start with this problam...

I have created a new moudle, with a public sub.
and when I try to excute this sub from a form it gives me an error of:

compile error: sub or function not defined

thats the idea of 'public' so it will be defined on all forms isn't ?

any ideas why it doesn't work ?
Sep 7 '07 #1
12 14971
FishVal
2,653 Expert 2GB
I have a bigger question but lets start with this problam...

I have created a new moudle, with a public sub.
and when I try to excute this sub from a form it gives me an error of:

compile error: sub or function not defined

thats the idea of 'public' so it will be defined on all forms isn't ?

any ideas why it doesn't work ?
Hi, zivon.

Believe it or not, but function/sub declared as public in code module may be invoked in any module. ;)
The reason why it is not working in your case may be more clear if you provide additional information.
Sep 7 '07 #2
missinglinq
3,532 Expert 2GB
Sorry, but in order for a Public sub/form to be called from any form in a database, it has to be placed in a standard module, not in a code module behind a form! From the object dialog box, Modules - New and enter your code for the sub. When prompted to name the module, name it anything except the same name as the sub/function!

Linq ;0)>
Sep 7 '07 #3
zivon
59
thats what I was thinking, but it doesn't work : \

here is what I'm trying
a moudle called 'email'

Public Sub test()
MsgBox ("this is a test")
End Sub

on the form:

Private Sub test_Click()
test
End Sub
Sep 8 '07 #4
missinglinq
3,532 Expert 2GB
This drove me a nutz for a bit, but I needed the distraction! The problem is

Public Sub test()
MsgBox ("this is a test")
End Sub

on the form:

Private Sub test_Click()
test
End Sub

You were confusing Access by calling both the public sub and the control you were using to call it the same thing! Once I changed one of them the problem was resolved!

Linq ;0)>
Sep 8 '07 #5
zivon
59
I change the name of the public sub to testing... and it still doesn't work...

same problam: "compile error: sub or function not defined"

I've also tried to change the name on the module to TesTing, to see if it also changes it on the form, and it does... : \
Sep 8 '07 #6
FishVal
2,653 Expert 2GB
I change the name of the public sub to testing... and it still doesn't work...

same problam: "compile error: sub or function not defined"

I've also tried to change the name on the module to TesTing, to see if it also changes it on the form, and it does... : \
Try to call it referencing explicitely to the module.
Expand|Select|Wrap|Line Numbers
  1. email.testing
Sep 8 '07 #7
zivon
59
email.testing

compile error: variable not defined

I think access hates me :)
Sep 8 '07 #8
FishVal
2,653 Expert 2GB
email.testing

compile error: variable not defined

I think access hates me :)
I've not succeded to reproduce your situation.
I suggest you to reproduce it in blank database made from scratch, zip it and attach to a post.
Sep 8 '07 #9
missinglinq
3,532 Expert 2GB
I agree! As I previously indicated, I couldn't reproduce the error either except when the sub and control being clicked shared names.

Linq ;0)>
Sep 8 '07 #10
zivon
59
I took your advice of trying to open a new db.
and it worked, then I figure out what the problam is, it wasn't a module what I was using... I'm not sure what it is, maybe a class module ?
anyway it had another icon.

thanks for everything ! :)
Sep 8 '07 #11
@FishVal
Worked... Thanks a lot... :) :)
Mar 24 '20 #12
ADezii
8,834 Expert 8TB
Actually, a Public Sub that exists in a Code Module behind a Form can be called since, under this context, it is actually a Method of the Form. You must first check and see if the Form is Loaded, and if it is, you must preface the Procedure with the Form Name. The following Code is fully operational and will illustrate this concept:
Expand|Select|Wrap|Line Numbers
  1. If CurrentProject.AllForms("Form2").IsLoaded Then
  2.   Call Forms("Form2").PublicSubInForm2
  3. End If
Mar 25 '20 #13

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

Similar topics

9
by: Banaticus Bart | last post by:
I wrote an abstract base class from which I've derived a few other classes. I'd like to create a base class array where each element is an instance of a derived object. I can create a base class...
0
by: john bailo | last post by:
I am attempting to create a c# program to iterate through the messages in an Outlook/Exchange public folder and extract the headers. My apologies to the VB/VBA groups, but you seem to have more...
6
by: Sahil Malik [MVP] | last post by:
Public Private Key Pairs - How do they work? ----------------------------------------------- I was looking at a presentation recently in which it was suggested that - User 1 Encrypts a message...
3
by: | last post by:
All the fields in webforms are automatically declared as protected. If I change them to public, they are converted back to protected. Why is this happening ? Thanks
2
by: Burak | last post by:
Hello, I have a web service that has a two user defined public classes. For sake of brevity, I'll write them as follows Public Class Service1 Public Class Class1 Public x as integer End...
4
by: Nick Dreyer | last post by:
Is it possible to see public class variables of a COM addin in Excel 97 VBA? I have successfully created the (Visual Basic 2003 .NET) COM and referenced it in an Excel 97 VBA project. The VBA...
5
by: D Witherspoon | last post by:
What is happening is that I have a class (ClassA) that inherits a class (ClassB) which inherits System.Net.Mail.MailMessage Project 1 references Project 2, Project 2 references Project 3. ...
2
by: Sky | last post by:
Hello: I'm trying to make sense of snk files, when to use, under what conditions to regenerate new ones,...can someone take a look if these statemes make sense? And then the final questions at the...
6
by: =?Utf-8?B?SmF5IFBvbmR5?= | last post by:
I am trying to access a Public property on a Master Page from a Base Page. On the content pages I have the MasterType Directive set up as follows: <%@ MasterType virtualpath="~/Master.master" %>...
2
by: fgh.vbn.rty | last post by:
Hi, I'm not sure if i'm asking the question correctly but anyway here it is. Say I have 3 classes - class A, class B, class R. 1) A and B are the building blocks and R is like a repository...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.