Running a Module

ddrew

seasoned user
Local time
Today, 17:42
Joined
Jan 26, 2003
Messages
911
I have a module (CR2Count) that I am trying to run from a subform. How do I code that in please? I have put CR2Count which is what I would do if it were a public function. But with a module I get Compile Error: Expected variable or procedure, not module. Thanks
 
Here is the code, it was written a Public Function on the Subform. But I want to use it globaley so tried to do it as a module:

Code:
Public Function CR2Count()
    Dim someText, onlyNull As Integer
    someText = 0
    onlyNull = 0
    For Each ctl In Forms![frmCR2WR].Controls
        If ctl.ControlType = 109 And Left(ctl.Name, 3) = "CR2" Then
            If Len(ctl.Value & "") = 0 Then
                onlyNull = onlyNull + 1
            Else
                someText = someText + 1
            End If
        End If
    Next ctl
    Form!frmCR2WR.Form!CountCR2s = (someText)
    Form!frmCR2WR.Form!AvailCR2s = (onlyNull)
End Function
 
I think you have used the same name for the module too.. I mean you have named the module as 'CR2Count', is that correct????

Try changing the name of the Module to 'CR2CountModule' or something else that would differentiate it from the function.. You will not get the error..
 
Just done that, I dont get the error now but it dosent zero the text boxes that show the qtys i.e. {AvailCR2s and CountCR2s) on the subform.
 
So the way you are accessing the field might be wrong.. Try either of these..

Forms![frmAssetManager]![frmCR2WR].Form![AvailCR2s]
or Form_frmAssetManager![frmCR2WR].Form![AvailCR2s]
or Forms("frmAssetManager")![frmCR2WR].Form![AvailCR2s]
 

Users who are viewing this thread

Back
Top Bottom