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?
detroitdrAsked:
Who is Participating?
 
peter57rConnect With a Mentor Commented:
It sounds like you have renamed your module to DOC - leave the modules names alone until you have a clear picture of how insignificant they are(:-)  So change it to something other than Doc.



 
0
 
Jorge PaulinoIT Pro/DeveloperCommented:
Agree wiht perter but try this inside your form code. This must work!

Option Compare Database

Public Function DOC()
    MsgBox "hello"
End Function

Private Sub Form_Load()
  Call DOC
End Sub

0
 
ImoutwestCommented:
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.
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
ImoutwestCommented:
Sorry jpaulino should have hit refresh. Do you know a Glenn Paulino?
0
 
Jorge PaulinoIT Pro/DeveloperCommented:
No, i'm from Portugal. I think he leaves far away! :-)
0
 
wsh2Commented:
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
0
 
detroitdrAuthor Commented:
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.
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
"Functions require a return value.. you have specified none"

Functions do not *require* a return value!  No such  requirement.

mx
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.