Link to home
Start Free TrialLog in
Avatar of detroitdr
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?
ASKER CERTIFIED SOLUTION
Avatar of peter57r
peter57r
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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

Avatar of Imoutwest
Imoutwest

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.
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
Avatar of detroitdr

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