• Conditionaly disable a control

    • This topic has 2 replies, 3 voices, and was last updated 15 years ago.
    Author
    Topic
    #468804

    I’ve search high and low.

    How would I go about disabling a Forms Control if the Control is not Null?

    What I have is Form with a Created Control which should have a date if the record is new. I have a Button for the user to open a calendar form that places the date into the Control. After the Control is updated with a date I want the Control and button to be disabled and view the Controls contents

    As a second question with this I have a Last Updated Control that when the record is updated I would like the date to populate the Control automatically.

    Can someone point me the direction of an answer

    Access 2002 will be moving to 2007

    Viewing 1 reply thread
    Author
    Replies
    • #1223037

      You can Disable a Control using this line of code

      Code:
      me.controlname.enabled=false

      Disabled controls look grey. If you don’t want it to look grey, then lock it when you disable it.

      Code:
      me.controlname.locked=true

      You need to put this code in two places.

        [*]Normally you use the After Update event of what you want to trigger it. But in this case you are doing that via a button, so the after update event will not fire. So you need to tack in on the end of the code that puts the date in.[*]The On Current of the form as well. This is so the control is locked when you revisit existing records. But here you need to enable/disable selectively.
      Code:
      if isnull(me.controlname) then
      me.controlname.enabled=true
      me.controlname.locked=false
      else
      me.controlname.enabled=false
      me.controlname.locked=true
      end if
      

      The Form itself has an After Update event. Use that to set the value of the Last Updated Control

      Code:
      me.[last updated] = Date
    • #1223092

      Is the last updated control a BOUND or an UNBOUND Control

      If it is Bound to a Field on the underlying recordset, you need to use the FORMS BEFORE UPDATE Event to set its value.

      If it is Unbound After Update is Fine.

    Viewing 1 reply thread
    Reply To: Conditionaly disable a control

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: