Results 1 to 5 of 5
  1. #1
    markjkubicki's Avatar
    markjkubicki is offline Competent Performer
    Windows 10 Access 2013 64bit
    Join Date
    Jul 2010
    Location
    Fire Island Pines, NY
    Posts
    496

    which is better code ?

    (or does it not matter) ?

    Code:
    Private Sub Form_Open(Cancel As Integer)
        With Me
            .cboGoToMfr.Visible = True
            .lblGoToMfr.Visible = True
            .cmdDelete.Visible = True
            .cmdNewRecord.Visible = True
    
            If Not IsNull(Me.OpenArgs) Then
                .cboGoToMfr.Visible = False
                .lblGoToMfr.Visible = False
                .cmdDelete.Visible = False
                .cmdNewRecord.Visible = False
                With .fsubManufacturer_info_entry
                       ' <...>
                End With
            End If
        End With
    End Sub
    -or-

    Code:
    Private Sub Form_Open(Cancel As Integer)
        With Me
            If Not IsNull(Me.OpenArgs) Then
                .cboGoToMfr.Visible = False
                .lblGoToMfr.Visible = False
                .cmdDelete.Visible = False
                .cmdNewRecord.Visible = False
                With .fsubManufacturer_info_entry
                       ' <...>
                End With
            Else
                 .cboGoToMfr.Visible = True
                 .lblGoToMfr.Visible = True
                 .cmdDelete.Visible = True
                 .cmdNewRecord.Visible = True
            End If
        End With
    End Sub
    -or-

    Code:
    Private Sub Form_Open(Cancel As Integer)
        With Me
            .cboGoToMfr.Visible = IsNull(Me.OpenArgs)
            .lblGoToMfr.Visible = IsNull(Me.OpenArgs)
            .cmdDelete.Visible = IsNull(Me.OpenArgs)
            .cmdNewRecord.Visible = IsNull(Me.OpenArgs)
    
            If Not IsNull(Me.OpenArgs) Then
                 With .fsubManufacturer_info_entry
                       ' <...>
                End With
            End If
        End With
    End Sub
    ...as always, with appreciation in advance,
    m.

  2. #2
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,397
    personally I go for the third option (using isNull) - less typing and less prone to making errors if there is a long list of controls that need properties modifying. If you want to save even more typing

    Code:
    dim v as boolean
    
        v=isnull(openargs)
    
        cboGoToMfr.Visible = v
        lblGoToMfr.Visible = v
        etc
    (the me predicate is not required as it is the default)


    the first option is probably the least efficient in that you are potentially setting the properties twice

    but with processors these days, doubt you would notice a difference

  3. #3
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    Why not just design as not visible, then only reverse if a condition is met? Or the opposite?
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    I would also recommend what Micron suggested. In addition, I would move the code from Form_Open to Form_Load
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  5. #5
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,397
    I don't disagree - they will either be visible or not anyway. However during designing some may be visible, some not - so you need to make sure it is one of the last actions of design to ensure they are set correctly

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 20
    Last Post: 10-13-2015, 09:05 AM
  2. Replies: 3
    Last Post: 10-16-2014, 08:49 AM
  3. Replies: 2
    Last Post: 06-28-2013, 12:58 PM
  4. Replies: 7
    Last Post: 05-28-2013, 09:11 AM
  5. Replies: 1
    Last Post: 05-04-2013, 12:19 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums