Make numerous controls visible

tucker61

Registered User.
Local time
Today, 14:41
Joined
Jan 13, 2008
Messages
344
I have a form where i select via a combo box if a product has been inspected, if it has, additional controls are then made visible.

If Me.Inspection_Completed = "Yes" Then
Me.Date_Inspection_Comp.Visible = True
Me.Date_Inspection_Comp = Me.Dateinsp
Me.Inspector.Visible = True
Me.Qty_Inspected.Visible = True
Me.OK.Visible = True
Me.Inspection_Outcome.Visible = True
Me.Qty.Visible = True
ElseIf Me.Inspection_Completed = "no" Then
Me.Date_Inspection_Comp.Visible = False
Me.Inspector.Visible = False
Me.Qty_Inspected.Visible = False
Me.OK.Visible = False
Me.Inspection_Outcome.Visible = False
Me.Qty.Visible = False"

i tried to put this in a function so i could call it on load, or on current etc, but cant seem to get it to work, apparently you cannot use the me. in a function.

Any ideas of a easy way to call this or do i need to tyoe out again and again.
 
If the function is in a standard module, you'd need the full form reference:

Forms!FormName.Inspection_Completed
 
Thanks for that.
 
If the function is in a standard module, you'd need the full form reference:

Forms!FormName.Inspection_Completed

An alternative to doing that would be to have your Function have a parameter that is a Form, and call it using Me for the value. The reason for doing this would be to allow the Common Function to be reusable between two or more forms. If you do not have this situation, then it would not be necessary.

-- Rookie

Code:
IN THE FORM VBA CODE (Perhaps On Current?)
 
Call DisplayFields(Me)
 
IN THE STANDARD VBA MODULE
 
Public Sub DisplayFields(TheForm as Form)
    If Me.Inspection_Completed = "Yes" Then
        TheForm.Date_Inspection_Comp.Visible = True
        TheForm.Date_Inspection_Comp = Me.Dateinsp
        TheForm.Inspector.Visible = True
        TheForm.Qty_Inspected.Visible = True
        TheForm.OK.Visible = True
        TheForm.Inspection_Outcome.Visible = True
        TheForm.Qty.Visible = True
    ElseIf Me.Inspection_Completed = "no" Then
        TheForm.Date_Inspection_Comp.Visible = False
        TheForm.Inspector.Visible = False
        TheForm.Qty_Inspected.Visible = False
        TheForm.OK.Visible = False
        TheForm.Inspection_Outcome.Visible = False
        TheForm.Qty.Visible = False
    End If
End Sub
 

Users who are viewing this thread

Back
Top Bottom