Results 1 to 6 of 6
  1. #1
    jlgray0127 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2011
    Location
    Central Illinois
    Posts
    185

    Forms VBA Check Values to enable correct check boxes

    I have a form that I have 4 check boxes on.
    By default, they are disabled. I want to check if there is a value in another text box to determine if the check box should be enabled. Simply stated, all I'm doing is checking for null. If null, remain disabled. If there is a value, enable = true.
    The code kinda works, but is very inconsistent. Sometimes enabling or not enabling, when it should. I feel like I'm missing something. Any help is greatly appreciated!

    Private Sub Form_Open(Cancel As Integer)
    If [MakePartKit] >= 0 Then
    MakeKit_Deliver.Enabled = True
    End If

    If [PFKit] >= 0 Then
    PFKit_Deliver.Enabled = True
    End If

    If [LineSideKit] >= 0 Then
    LinesideKit_Deliver.Enabled = True
    End If

    If [SubsKit] >= 0 Then
    MadeSub_Deliver.Enabled = True
    End If

    End Sub

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2019
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    Perhaps:

    MakeKit_Deliver.Enabled =Nz(Me.
    MakePartKit,0)>=0
    PFKit_Deliver.Enabled =Nz(Me.PFKit,0)>=0
    LineSideKit.Enabled =Nz(Me.LineSideKit,0)>=0
    MadeSub_Deliver.Enabled =Nz(Me.SubsKit,0)>=0


    in the forms OnCurrent event.

    But what is the purpose of the checkbox controls?
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Why not use the IsNull() function?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  4. #4
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2019
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    Quote Originally Posted by Welshgasman View Post
    Why not use the IsNull() function?
    I can't think of any good reason not to use the IsNull() function. If I'd thought of it, I might even have suggested it
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  5. #5
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Quote Originally Posted by Bob Fitz View Post
    I can't think of any good reason not to use the IsNull() function. If I'd thought of it, I might even have suggested it
    Well O/P could combine it with your post?
    Plus I posted that before seeing your post. It was addressed to the O/P

    Me.ControlName.Enabled = NOT IsNull(Me.OtherControlName)
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Reason for instability possibly because Null cannot be compared to anything else because there is nothing to compare. However, expression of Null >=0 should be treated as a False result because it certainly can't return True.

    Never build a comparison expression with equivalent operators when Null could be an input. Use IsNull(), Nz() or in SQL IS NULL.

    Note suggestions using qualifier prefix of Me. Can wrap in With Me structure.
    Code:
    With Me
        .ControlName.Enabled = NOT IsNull(.OtherControlName)
    ...
    End With
    
    Could use With anyobjectreference to condense code.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Replies: 2
    Last Post: 10-07-2020, 10:30 AM
  2. Replies: 41
    Last Post: 12-06-2016, 08:40 AM
  3. Check box based on values of other check boxes?
    By Michael.Reynolds1775 in forum Forms
    Replies: 3
    Last Post: 03-25-2015, 12:58 AM
  4. Replies: 3
    Last Post: 08-15-2013, 10:43 AM
  5. Replies: 3
    Last Post: 09-29-2010, 09:31 AM

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