VBA code to disable field on form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Jackie Craddock

    #1

    VBA code to disable field on form

    I wrote a little database to keep track of employee time. After the pay period ends, we need to be able to programically change specific fields on the form to read-only.

    Specifically, when the payroll period for October 17-30 ends, I'd like to create a button the payroll clerk can hit that will make the fields for those dates to change from Enabled=Yes, to Enabled=No. I'd like it to start on October 17, then step through the procedure 13 more times.

    I'mve signed up for VBA classes, but they haven't started yet. I can program a little, but I'm not a proficient programmer right now, and I currently lack the skills to write this code.

    Any suggestions?
  • dsatino
    Contributor
    • May 2010
    • 393

    #2
    Create a button on the form.
    In the onClick event of that button put something like this:
    Code:
    Me.Controls("TEXTBOXNAME").Enabled = False

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32669

      #3
      You can use either :
      Code:
      Me.TextBoxName.Locked = True
      or :
      Code:
      Me.TextBoxName.Enabled = False
      The principle difference being that .Locked = True disables use but .Enabled = False does that, as well as showing the control as greyed out somewhat.

      Comment

      • OldBirdman
        Contributor
        • Mar 2007
        • 675

        #4
        I assume the data is normalized. The time data would be in a related table with a foreign key to the employee table. I would expect an UPDATE Query would be appropriate here to mark each record within the time period (October 17-30) in the example given. This would require a Completed field (Yes/No) on each day's record be updated to 'Yes' in the UPDATE query.

        If the time data when shown in form view is Continuous Forms, then Conditional Formatting will be necessary to set .Enabled to False for the appropriate fields.

        If the time data is in the employee table, and the form view is always Single Form, then Conditional Formatting is not necessary. .Enabled can be set in the form's OnCurrent event.

        Additionally, there should be a method to unlock/enable the fields again if an error is discovered that must be fixed.

        Comment

        Working...