Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2004

    Unanswered: Dim and Visible problem?

    I am attempting to automate the process of displaying certain fields and labels on a form based on a tick box selected at the side ("Not Applicable")

    Here is the code I am using but I can't seem to get it to work, it errors with 438 errors among other errors.

    Dim NA, NALabel, NAMain, NADate, NABy 
    NA = [FacAlarmNA]
    NALabel = [FacAlarmNALabel]
    NAMain = [FacAlamrm]
    NADate = [FacAlarmDate]
    NABy = [FacAlarmBy]
    If NA = True Then
        NALabel.Visible = True
        NAMain.Visible = False
        NADate.Visible = False
        NABy.Visible = False
        NAMain = False
        'NADate = ""
        'NABy = ""
        NALabel.Visible = False
        NAMain.Visible = True
        NADate.Visible = True
        NABy.Visible = True
        End If
    As I have 10 or more tick boxes (NA) on each form linked to different fields each, this way I could change the top part to the new fields under the click event of each NA tick box and that way saves me less work when doing a whole page of NA tick boxes and fields.
    It works when I manually do this, what I mean is when I type the fields into the above instead of linking them it works fine - just wanted to automate the process a bit, saves me typing the fields into 20 lines, rather than just the first 5 as above...

    Any help appreciated.

  2. #2
    Join Date
    May 2003
    Provided Answers: 5
    try removing the dim statements

    try using

    [FacAlarmNA].visible instead of the dim and also remember - you cannot hide a control that has the focus - so before hiding a control move the focus to another control - preferably the next control that needs to evaluated

    also that error is usually associated with data binding

    and sometimes if evaluating a yes/no field I always use -1 or 0 or if it is true/false on the form I use cint(truefalsefieldname) to get the numeric value -1 or 0
    Dale Houston, TX

  3. #3
    Join Date
    Mar 2004
    that doesn't help. the idea of the the dim statements is so I only have to change the top 5 lines rather than all the lines below that - i have it working fine on [FacAlarmNA].visible - is there a way to link it to a stored statement? only for each click, so don't need to store it beyond that command.

  4. #4
    Join Date
    Jan 2007
    Provided Answers: 12
    Here's my 2cents.

    1) OPTION EXPLICIT! You haven't declared a datatype for your Dimmed variables! Best practice is to ALWAYS declare the datatype - best way to do this is to add
    Option Explicit
    At the top of each module etc (right below the "Option Compare...")

    2) Make this into a function - you can make a function with an array parameter (or fixed number) of arguements to do the job for you.

    Here's some pseudo code written entirely from my brain box (i.e. it won't work right off the bat )
    Public Function exampleByGeorgeV(ParamArray arrayValues() As Variant)
    Dim i As Integer
        For i = 0 To UBound(arrayValues())
            Me(arrayvallues(1)).Visible = False
        Next i
    End Function
    Call the function like so
    Call exampleByGeorgeV(field1, field2, field3, .... ,fieldN)
    Home | Blog

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts