Results 1 to 4 of 4
  1. #1
    ballj_35 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2010
    Location
    Columbus Oh
    Posts
    25

    Protect all fields, then on button click, open them up to editing

    I would like to protect all fields when a user enters a screen. Then allow them to click on a button and make the fields available for editing. Another button to make the fields on the screen protected again.

    My thoughts were on the Form_Load and Form_Activate, make all of the fields Enabled = FALSE. But my issue is when I am creating a button for the Form, what type of Button is it going to be. I use the wizard for the control, but I do not know what to make it.

    What should happen is that when the user clicks on the Edit Record button, I will just make the click action set the fields to Enabled = True. When the user clicks on Protect recored button, it will set the fields Enabled = False.

    Cna someone plz help me on where I should be doing this best or any other ideas?


    Thanx in advance.


    Jerry

  2. #2
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    When you create your button, don't use the Wizard. Just cancel out of it.
    Then, select the button and Open the Properties [button on top of screen].
    There you can 'Name' and 'Caption' the Button.

    Next . . .
    Click the 'Event Tab on the Property Sheet and
    Click the '[...]' to the right of the 'On Click' row and
    Select 'Code Builder' . . . and a VBA Code Window will open.

    You can use code something like this between the two lines that Access puts in the VBA Code Editor for you:
    Code:
    Dim ctl As Control
    For Each ctl In Me.Controls
        If (ctl.ControlType = acTextBox) Then
            ctl.Enabled = False
        End If
    Next ctl
    You can read a nice article on this on this web site: http://www.tek-tips.com/faqs.cfm?fid=5010

    You could also name each Text Box individually and say something like this:
    Me.TextBox_1.Enabled = False
    Me.TextBox_2.Enabled = False
    Me.TextBox_3.Enabled = False
    Me.TextBox_4.Enabled = False
    But looping through all the controls on the Form and disabling the ones that are Text Boxes is a useful technique to learn - and it's pretty simple as well.

    Let me know if you need any help!

  3. #3
    Missinglinq's Avatar
    Missinglinq is online now VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    A variation of this method:

    If you only want to Disable some Controls on a Form, or even some Controls of a certain type , but not all Controls:

    In Form Design View

    1. Press and Continue Holding down the <Shift> key
    2. Select all Controls you want to Enable/Disable
    3. Release the <Shift> key
    4. Right-Click to open Menu
    5. Click on Properties - Other
    6. In the Tag Property Box enter the word Target (no Quotation Marks!!!)


    Now, in code, to Disable only the 'tagged' Controls
    Code:
    Dim ctl As Control
    For Each ctl In Me.Controls
        If ctl.Tag = "Target" Then
            ctl.Enabled = False
        End If
    Next ctl
    And to reverse this, of course, you just change

    ctl.Enabled = False

    to

    ctl.Enabled = True

    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
    Missinglinq's Avatar
    Missinglinq is online now VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Actually, in re-reading your post, two things occurred to me.

    First off, you wouldn't want your Controls to be Disabled except when you clicked on your 'edit' button, as Enable set to False causes the Fields to be greyed out! Not a very nice display option.

    Secondly, if you want all Controls/Fields locked, after the initial Record is saved, until you use the 'edit' button, you can do that with two lines of code:
    Code:
    Private Sub Form_Current()
      Me.AllowEdits = False
    End Sub
    
    Private Sub EditButton_Click()
      Me.AllowEdits = True
    End Sub
    This will allow you to enter New Records, but once you move to another Record, enter another New Record or Close the Form, that Record will be 'locked,' until the EditButton is clicked. Once you move to another Record, its Controls will be locked. If you were to depend on the user resetting the Controls to the 'locked position,' as it were, you'd really be right back where started, with the ability to accidentally change something back in place!

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

    All posts/responses based on Access 2003/2007

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

Similar Threads

  1. Press a button to combine two fields to open a PDF
    By Douglas Post in forum Programming
    Replies: 4
    Last Post: 02-11-2012, 02:02 PM
  2. Report does NOT open on BUTTON CLICK
    By taimysho0 in forum Programming
    Replies: 3
    Last Post: 01-04-2012, 02:38 PM
  3. Click button to open a new image
    By tia in forum Forms
    Replies: 2
    Last Post: 10-10-2011, 11:03 AM
  4. P/W Protect & Open Database Using VBA
    By DrGlenn in forum Programming
    Replies: 1
    Last Post: 08-06-2010, 08:08 PM
  5. Replies: 1
    Last Post: 03-03-2010, 07:29 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