Compile error - Expected variable or procedure, not module

Christine Pearc

Christine
Local time
Today, 23:48
Joined
May 13, 2004
Messages
111
I’m receiving the following error message in one of my modules/procedures “Compile error - Expected variable or procedure, not module."

Here’s the background and code:

The module CheckForNulls checks for null values in form fields. The code is in a module because it should be available to all forms “on the fly”. The module is called by Private Sub cmdSend_Click() event, where it says
Cancel = CheckForNulls(me.form).

Due to the error message, I tried changing this to the following, but still get the error
Dim X As Boolean
X = CheckForNulls(Me.Form)

Back on the form, if CheckForNulls = False (no incomplete records were found), then some other routines take place.

PHP:
Public Function CheckForNulls(frm as form) as boolean
    Dim ctl As Control
    Dim intMsgResponse As Integer
    ' Loop through all the controls on the form
    For Each ctl In frm.Controls
        ' Check the tag property
        If ctl.Tag = "RequiredField" Then
            ' Check this control has a value
            If ctl = "" Or IsNull(ctl) Then
                ' No Value - Cancel the update event
                CheckForNulls = True

                'Exit loop when an incomplete required field is found
                Exit For
            End If
        End If
    Next
    ' Check to see if a required field was blank and inform the user
    If CheckForNulls = True Then
        MsgBox "Please fill in all required fields."
    End If
End Function

Could someone look at this to help pinpoint what is wrong?

Christine
 
1 This should be a sub not a function (it doesnt have the function to return the boolean to your original code, it handles the message and all itself).

2 Your Module has the same name as your function, get a naming convention in place (search the forum if that sounds alien to you)! Rename the module to mdlCheckForNulls

Greetz
 
Complile error - Expected variable or procedure, not module

Thank you for that. Sorry if this is going to be a silly question, but I'm very new to all this.

I've changed the name of the module, as you suggested and changed the code to this
Public Sub CheckForNulls(frm As Form)
.....
End Sub

Everything else in the module is the same. It still doesn't work and I'm sure it's probably something silly.

I had two options for "calling" the procedure, none of which work:

1. Cancel = mdlCheckForNulls(Me.Form)

2. Dim X As Boolean
X = CheckForNulls(Me.Form)

After checking for nulls and control returns to my form, I want to do some stuff if CheckForNulls = False:

If CheckForNulls = False Then

So, you see I'm still in the dark. Your further assistance will make the end of this work day a success. Hope to hear from you soon!

Christine
 
Still awaiting help - Compile error: Expected variable or procedure, not module

I hate to appear impatient, but could someone respond soonest concerning my problem and last post? I played with the code this weekend, to no avail. :confused:

Thanks so much,
Christine
 
I don't know why namlian said it should be a Sub I don't know; he must have been having an off day as it perfectly obvious that it is - and should be - a function.

Don't send Me.Form to the function. Send Me
 
Thank you. I'm still getting the same compile error.

In the form that calls the function, I've changed it as I *think* you said to do about changing the line to "send" the function call:

Private Sub cmdSend_Click()

' Call the module mdlCheckForNulls to ensure all form fields are complete.
Cancel = mdlCheckForNulls(Me)

In the module (called mdlCheckForNulls), it reads...

Public Function CheckForNulls(frm As Form) As Boolean

Dim ctl As Control
Dim intMsgResponse As Integer
' Loop through all the controls on the form
For Each ctl In frm.Controls
...etc.
End Function
 
Can you upload a copy of the relevant components in a database? Change any confidential data to dummy data.
 
Oops, the file didn't attach. Here it is.

BTW, I tried Rich's suggestion

If Not mdlCheckForNulls(Me) Then
Cancel = True
End If

but still receive the same error.
 

Attachments

looks like you have been merging to functions somehow :-) try
Public Function CheckForNulls(frm As Form) As Boolean
Dim ctl As Control
Dim intMsgResponse As Integer
CheckForNulls = False
' Loop through all the controls on the form
For Each ctl In frm.Controls
' Check the tag property
If ctl.Tag = "RequiredField" Then
' Check this control has a value
If ctl = "" Or IsNull(ctl) Then
' No Value - Return True
CheckForNulls = True
'Exit loop when an incomplete required field is found
Exit For
End If
End If
Next
End Function

Peter
 
Wouldn't it be simpler just to set the fields' Required property to True at table level?
 
You still had the wron call from the form,
Cancel = mdlCheckForNulls(Me)
should be
Cancel = CheckForNulls(Me)

Also you have not dim'ed the Cancel as a variable so that will thow you an error next!

Peter

Edit - In fact as Cancel is a reserved word it is probably better not to use it anyway!
 
le error - Expected variable or procedure, not module

Ordinarily, yes. However, at the request of users, I've had set up the form so that users can create a Corrective Action Request (CAR) and leave it incomplete until a later time when they can come back to edit it. Unfortunately, this will happen quite frequently.

When they press the Send button, this is when the checks need to be made to ensure they haven't left anything blank.

Christine
 
Expected variable or procedure, not module - SOLVED!

I am so pleased to report that the problem is solved! Many, many thanks to all of you who helped. Peter's last comment about Cancel et al was the final piece in the puzzle. You guys are the best!

Christine
XOXOX!!
 

Users who are viewing this thread

Back
Top Bottom