Class Module - object doesnt support this property or method.

thmsjlmnt3953

Registered User.
Local time
Today, 22:32
Joined
May 20, 2014
Messages
120
I have the following in a class module (as it supports the me.controls format)

Code:
Public Function CheckForm()
 For Each ctl In Me.Controls
        Select Case ctl.ControlType
            Case acTextBox, acComboBox, acListBox, acCheckBox
                If Len(Nz(ctl.Value, vbNullString)) = 0 Then
                        With ctl
                            .BorderColor = vbRed            ' Red
                            .BorderWidth = 1                ' 1 point
                            .BorderStyle = 1                ' Solid
                        End With
                End If
        End Select
    Next ctl
    MsgBox "Missing required information." & vbCrLf & "Please fill in all missing information and try again.", vbCritical, "Can't Save"
Exit Sub
End Function

im trying to call it with the following

Code:
Dim CheckTheForm As New clsCheckForm
CheckTheForm

however im getting the above error - it works when ran inside the sub and not in a class but id like it in a module to use in every form.
 
You need to pass the form to it

Public Function CheckForm ( MyForm as Form)

and replace the Me with MyForm


and call it

CheckForm Me
 
I would expect to see a call like . . .
Code:
[COLOR="Green"]'here you declare and create the instance[/COLOR]
Dim CheckTheForm As New clsCheckForm
[COLOR="Green"]'and here you call a method that belongs to that class[/COLOR]
CheckTheForm.CheckForm
 
MarkK is much more into obejcts than I am so just follow what he says
 
You make a good point though, spike. The custom class will need a reference to the form at some point, and I don't see in the posted code where that happens.
 
... id like it in a module to use in every form.
Chaps I think the poster wants to have it in a Module, not a Class Module.

So thmsjlmnt3953, put the following in a Module (just a Module, not a Class Module):
Code:
Public Function CheckForm(frm As Access.Form)
    Dim ctl As Access.Control
    
    For Each ctl In frm.Controls
        With ctl
            Select Case .ControlType
                Case acTextBox, acComboBox, acListBox, acCheckBox
                    If Len(.Value & vbNullString) = 0 Then
                        .BorderColor = vbRed            ' Red
                        .BorderWidth = 1                ' 1 point
                        .BorderStyle = 1                ' Solid
                    End If
            End Select
        End With
    Next ctl
    
    MsgBox "Missing required information." & vbCrLf & _
           "Please fill in all missing information and try again.", _
           vbCritical, _
           "Can't Save"
End Function
And call it in any of your form like this:
Code:
CheckForm Me
 

Users who are viewing this thread

Back
Top Bottom