detroitdr
asked on
function in Access 2003 error
ok I'm not getting functions I guess. (perhaps I'm just really an idiot...)
I have a form and ON LOAD I have:
Private Sub Form_Load()
DOC
.... end sub
(I have a function:)
Public Function DOC()
MsgBox "hello"
End Function
I'm just trying to understand how this work.... but I get the error:
Compile error: Expected variable or procedure, not module
why?
I have a form and ON LOAD I have:
Private Sub Form_Load()
DOC
.... end sub
(I have a function:)
Public Function DOC()
MsgBox "hello"
End Function
I'm just trying to understand how this work.... but I get the error:
Compile error: Expected variable or procedure, not module
why?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Being a bit hard on yourself, we all have to start at the beginning (and I'm still pretty close to that).
Go to the modules tab, what is the name of your module, I typically give it the title modWhatItsAbout
Open the module, your function should look something like this:
Option Compare Database
Option Explicit
Public Function DOC()
MsgBox "hello"
End Function
Now hit Ctrl & G (at the same time) opens the immeidate window.
Enter the following: and press enter.
?doc()
Should open up the message box and say hello.
The problem that you having is how you're calling the function in you open form.
Go to the modules tab, what is the name of your module, I typically give it the title modWhatItsAbout
Open the module, your function should look something like this:
Option Compare Database
Option Explicit
Public Function DOC()
MsgBox "hello"
End Function
Now hit Ctrl & G (at the same time) opens the immeidate window.
Enter the following: and press enter.
?doc()
Should open up the message box and say hello.
The problem that you having is how you're calling the function in you open form.
Sorry jpaulino should have hit refresh. Do you know a Glenn Paulino?
No, i'm from Portugal. I think he leaves far away! :-)
Functions require a return value.. you have specified none.. try this as an example:
Public Function MyFunction() AS String
MyFunction = "HELLO WORLD!"
End Function
And to use it:
MsgBox MyFunction
Public Function MyFunction() AS String
MyFunction = "HELLO WORLD!"
End Function
And to use it:
MsgBox MyFunction
ASKER
thank-you all for your input... Peter you hit it right on the head. I named my module DOC. That was causing the error. Thank-you all again.
"Functions require a return value.. you have specified none"
Functions do not *require* a return value! No such requirement.
mx
Functions do not *require* a return value! No such requirement.
mx
Option Compare Database
Public Function DOC()
MsgBox "hello"
End Function
Private Sub Form_Load()
Call DOC
End Sub