• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 500
  • Last Modified:

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?
0
detroitdr
Asked:
detroitdr
1 Solution
 
peter57rCommented:
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
 
jpaulinoCommented:
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
ImoutwestCommented:
Sorry jpaulino should have hit refresh. Do you know a Glenn Paulino?
0
 
jpaulinoCommented:
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 MVP, Access and Data Platform)Commented:
"Functions require a return value.. you have specified none"

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

mx
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now