By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,164 Members | 969 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,164 IT Pros & Developers. It's quick & easy.

Public sub

P: 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
Share this Question
Share on Google+
10 Replies


FishVal
Expert 2.5K+
P: 2,653
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
Expert 2.5K+
P: 3,532
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

P: 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
Expert 2.5K+
P: 3,532
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

P: 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
Expert 2.5K+
P: 2,653
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

P: 59
email.testing

compile error: variable not defined

I think access hates me :)
Sep 8 '07 #8

FishVal
Expert 2.5K+
P: 2,653
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
Expert 2.5K+
P: 3,532
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

P: 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

Post your reply

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