Results 1 to 9 of 9
  1. #1
    Kivan is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2012
    Posts
    27

    Enabling fields in form

    Hi,

    I have a continuous form with History of tasks. I have the fields: Id, Date, Task, TaskFinished(Yes/No), Employee. I want field TaskFinished to be enabled after user write a Task (and it should be disabled if there is no task). Same happens to fields TaskFinished and Employee. I wrote the code:

    Code:
    Private Sub Form_Current()
    
    If IsNull(Me![Task]) Then
        Me.TaskFinished.Enabled = False
    ElseIf Not IsNull(Me![Task]) Then
        Me.TaskFinished.Enabled = True
    End If
    
    If Me![TaskFinished].Value = False Then
        Me.Employee.Enabled = False
    ElseIf Me![TaskFinished].Value = True Then
        Me.Employee.Enabled = True
    End If
    
    End Sub
    Here is the problem:


    If I write something in field "Task" not only current "TaskFinished" is enabled, but it looks like all of the "TaskFinished" are enabled. Obviously same thing happens to TaskFinished and Employee (If I confirm that task if finished all Employee fields are enabled). However in both examples it is only graphic effect, you cant really write any values. How to fix it?

    And another thing. How to enable "TaskFinished" field immediately after writing sth in "Task" field. If I set requery command after update in "Task" field, it seems that I have to click somewhere to really requery it. Any solution?

    I have attached a simply example of this database.

    Thanks for your time.
    Attached Files Attached Files

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,952
    The AfterUpdate event of textbox Task and TaskFinished checkbox needs to be a function, macro, or [Event Procedure]. What you have is =[requery] which is meaningless.

    The form Current event triggered an error and form appeared corrupted so I had to rebuild to get rid of error.

    This is the nature of continuous form. If you change the property of control it is applied to ALL instances of the control for all records. This is because there really is only one control (as is evident in design view).
    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.

  3. #3
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Easiest way to do this kind of thing in a Continuous View or Datasheet View Form (or even in a Single View Form, really) is to use Conditional Formatting. Assuming that the name of the Control that holds the Task Field is, actually, Task,

    In Form Design View

    1. Hold down <Shift> and click on each Control that you want conditionally Enabled/Disabled.
    2. Click on the 'Conditional' Icon on the Ribbon
    3. Under 'Condition1' select Expression Is
    4. In the condition box enter Nz([Task],"")=""
    5. Now click on the 'Enable/Disable' Icon (the last Icon, to the right of the Back Color Icon)
    6. Click on OK

    You should now be set. It will Enable the Controls as soon as you enter data in the Task Field and leave the Field, and they will be Enabled/Disabled as is appropriate, for each Record.

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,952
    Rats! That is the second time I overlooked Enable/Disable option of conditional formatting. Access 2010 expanded Conditional Formatting to allow up to 50 conditions.
    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.

  5. #5
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Enable/Disable is kind of an odd-man-out situation, when you think about it! Everything else is purely 'formatting' as in setting the 'appearance' of a Control, rather than setting the 'function,' or lack thereof, of a Control!

    And, of course, this is really the one exception to the 'you can only use Conditional Formatting for Continuous/Datasheet Forms!' You can actually do this particular task, in code, if you're willing to simply Disable the Control without 'graying it out.' But you have to Lock the Control, as well, and as I said, it won't 'appear' Disabled.

    Code:
    Private Sub Form_Current()
     
     If Nz(Me.Task, "") = "" Then
      
      TaskFinished.Enabled = False
      TaskFinished.Locked = True
     
     Else
      
      TaskFinished.Enabled = False
      TaskFinished.Locked = True
     
     End If
      
    End Sub


    This works because, as you move from Record-to-Record, the Control will be Enabled/Locked appropriately for that Record, and nothing changes in the appearance of the Control when the two Properties are used in tandem, like this.

    Of course, even simpler, assuming you simply don't want to allow data entry to occur conditionally, would be to only use the Lock Property.

    Linq ;0)>
    Last edited by Missinglinq; 08-21-2012 at 11:49 AM.
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  6. #6
    Kivan is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2012
    Posts
    27
    Thank you guys !
    It works perfectly, but I had to make some changes in your solutions, because it didnt work as it should. So for the guys who will look at this topic in the future. Correct me If Iam wrong, here is what I made :

    I couldnt format TaskFinished field so I didnt use this Nz([Task],"")="" , but btw shouldnt it be Nz([Task])="" ? So I used your code, but I had to correct it and here is it:
    Code:
    If Nz(Me.Task, "") = "" Then
      
      TaskFinished.Enabled = False
      TaskFinished.Locked = True
     
     Else
      
      TaskFinished.Enabled = True
      TaskFinished.Locked = False
     
     End If
    I also used this conditional Nz([TaskFinished])=FALSE, in the employee field. After those changes looks like everything works fine.

    Thank you again .

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,952
    Linq's Nz syntax is correct. This would have same result:

    If [Task] & "" = "" Then
    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.

  8. #8
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Nz([Task],"")=""

    and

    Nz([Task])=""

    are actually the exact same statement, so either would work!

    That's because when using the Nz() Function, if the Field in the First Parameter, in this case Task, is Text (which it is) the Default for the Second Parameter is a Zero-Length String, i.e. "".

    So they both work, as does June7's

    [Task] & "" = ""

    and

    Nz(Me.Task, vbNullString) = vbNullString

    as well as two or three other hacks that slip my mind, at the present.

    Sorry about the code in the Else clause; I copied and pasted it from the If clause and forgot to reverse the settings for the Else part! It's very good that you spotted it!

    Good luck with your project!

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  9. #9
    Kivan is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2012
    Posts
    27
    I belive it's the same Nz([Task],"")="" , but for some reason I was receiving error when I tried to use it, so I had to change it.

    Thanks for help .

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

Similar Threads

  1. Enabling and disabling fields
    By SgtSaunders69 in forum Programming
    Replies: 9
    Last Post: 12-27-2011, 06:11 PM
  2. Replies: 1
    Last Post: 11-21-2011, 07:58 AM
  3. Disabling and Enabling subforms
    By vt800c in forum Programming
    Replies: 3
    Last Post: 05-24-2011, 07:37 AM
  4. Replies: 2
    Last Post: 01-15-2011, 10:56 AM
  5. Enabling a control and moving to a new tab in vba
    By MuskokaMad in forum Programming
    Replies: 1
    Last Post: 03-14-2010, 05:30 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