Page 2 of 2 FirstFirst 12
Results 16 to 23 of 23
  1. #16
    Micron is online now Very Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,424
    OK - my recollection was the biggest issue. It's not ctl.Type - it's ctl.ControlType


    However, I cannot get the expected result on the logical test AND <> 0 in conjunction with the controltype test unless I nest it as 2 If blocks. Thus the Select Case construct becomes decidedly more elegant. That is not all. There would be an issue if a check box was initially Null, as this cannot be compared to 0 or any other value. So the following seems to work:
    Code:
    Dim ctl As Control
    
    On Error Resume Next
    
    For Each ctl In Me.Controls
      Select Case ctl.ControlType
        Case acTextBox, acComboBox
          ctl.Enabled = Not IsNullEmpty(ctl)
        Case acCheckBox
          ctl.Enabled = Not Nz(ctl <> 0, False) 
      End Select
    Next
    It works for me if the check is Null, True or False, bound or not. Sorry - I usually warn about code that's untested, but in my code post I didn't declare that.
    Last edited by Micron; 06-04-2017 at 09:34 PM. Reason: grammar
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  2. #17
    gint32 is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Jan 2015
    Location
    Australia
    Posts
    116

    .

    Thanks very much for your much appreciated efforts, As yes it seems to almost work , the only issue I with it is that the code greys out the blanks .
    Unfortunately, it over my head as whats actually happening with the code you supplied, so I can't figure how to swap the code around, see below for what i am using.

    I tried swapping one line for this ..
    Code:
    'If IsNull(ctl) Or ctl = "" Then IsNullEmpty = False
    Code:
    Private Sub Command6_Click()
    
    '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    
    Dim ctl As Control
    
    On Error Resume Next
    Stop
    For Each ctl In Me.Controls
      Select Case ctl.ControlType
        Case acTextBox, acComboBox
          ctl.Enabled = Not IsNullEmpty(ctl)
        Case acCheckBox
          ctl.Enabled = Not Nz(ctl <> 0, False)
      End Select
    Next
    
    End Sub
    '<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    
    
    Public Function IsNullEmpty(ctl As Control)
    IsNullEmpty = False
    If IsNull(ctl) Or ctl = "" Then IsNullEmpty = True
    'If IsNull(ctl) Or ctl = "" Then IsNullEmpty = False
    End Function
    Last edited by gint32; 06-04-2017 at 10:05 PM. Reason: typo

  3. #18
    gint32 is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Jan 2015
    Location
    Australia
    Posts
    116
    Quote Originally Posted by Micron View Post
    OK - my recollection was the biggest issue. It's not ctl.Type - it's ctl.ControlType
    However, I cannot get the expected result on the logical test AND <> 0 in conjunction with the controltype test unless I nest it as 2 If blocks. Thus the Select Case construct becomes decidedly more elegant. That is not all. There would be an issue if a check box was initially Null, as this cannot be compared to 0 or any other value. So the following seems to work:
    Code:
    Dim ctl As Control
    
    On Error Resume Next
    
    For Each ctl In Me.Controls
      Select Case ctl.ControlType
        Case acTextBox, acComboBox
          ctl.Enabled = Not IsNullEmpty(ctl)
        Case acCheckBox
          ctl.Enabled = Not Nz(ctl <> 0, False) 
      End Select
    Next
    It works for me if the check is Null, True or False, bound or not. Sorry - I usually warn about code that's untested, but in my code post I didn't declare that.
    Many thanks for your suggestion Once Again.

    Not that I fully understand how your code works. But, I amended the lines by removing the >>>.. Not..<<< in your suggested ,but now I am stumped as it now throws an error within the function..specifically at the following
    Code:
    If IsNull(ctl) Or ctl = ""
    ..stating that the expression You entered has a field, control, or property name that Microsoft access can't find. Doesn't make sense as nothing is hidden (for it not to find)...Hey, What I highly informative error message as always from M.S ...So my question is ....Can anyone suggest how to fix or advise/amend to display each controls name as it loops through them......thanks

  4. #19
    gint32 is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Jan 2015
    Location
    Australia
    Posts
    116

    enabling and disabling froms controls

    Many thanks everyone who contributed to this issue, I finally got a working version going(although not the greatest of coding structure I must admit) in my part. So for a continuation of this please see my post on another most helpful forum at http://www.utteraccess.com/forum/ind...wtopic=2044083. I have also uploaded a working test solution for anyone who might be interested in using
    Attached Files Attached Files

  5. #20
    Micron is online now Very Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,424
    this seems to work in you db copy
    For Each ctl In Me.Controls
    Select Case ctl.ControlType
    Case acTextBox, acComboBox
    ctl.Enabled = IsNullEmpty(ctl)
    Case acCheckBox
    ctl.Enabled = Nz(ctl <> 0, False)
    End Select
    Next
    Reversing the function value probably would do the same thing. If you're happy with the current state, that's all that really matters I guess.
    Good luck!

  6. #21
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Quote Originally Posted by Micron View Post
    OK - my recollection was the biggest issue. It's not ctl.Type - it's ctl.ControlType
    @Micron,
    I can't believe that I also missed that.
    As a matter of fact, I just wrote code similar about a week ago.

  7. #22
    Micron is online now Very Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,424
    Quote Originally Posted by ssanfu View Post
    @Micron,
    I can't believe that I also missed that.
    As a matter of fact, I just wrote code similar about a week ago.
    A sign of age more so than the ages? That's my excuse.
    Last edited by Micron; 06-06-2017 at 02:45 PM. Reason: spelin
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  8. #23
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Agreed!!!!

Page 2 of 2 FirstFirst 12
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 9
    Last Post: 03-07-2017, 02:49 PM
  2. Replies: 12
    Last Post: 06-05-2015, 04:27 PM
  3. Replies: 8
    Last Post: 05-06-2014, 02:46 PM
  4. Replies: 17
    Last Post: 04-07-2014, 07:48 PM
  5. Fill textboxs with data from a query
    By Bkgabbert in forum Queries
    Replies: 1
    Last Post: 05-25-2012, 04:09 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