Results 1 to 7 of 7

Thread: Unlock by ID

  1. #1
    Join Date
    Dec 2004
    Posts
    3

    Unanswered: Unlock by ID

    Hi all,

    Right now I have a form in datasheet view. When the form loads I have some vb code that locks all of the datasheet fields so the user doesn't screw anything up.

    Ideally what I would like to do is enable each field by giving them an "edit" button and unlock only that field if clicked.

    I'm a VBA novice at the moment so take it easy on me. I'm coming from a PHP world so I'm not blind either = )

    If I had any idea of how the code would flow I would throw down an answer but...

    Thanks in advance.

  2. #2
    Join Date
    Nov 2004
    Posts
    32

    Unlock fields

    create an on click event procedure for the button that is meant to unlock the particular field and type the following code:

    me.<field name>.locked = false
    me.<field name>.enabled = true

    where as <field name> is replaced useing the name of the text box control to be unlocked.

    I must say though in a normal form this would probably cause you to create a lot of buttons and probably crowed the form. Maybe it would be better to use just one button that unlocks all of the fields or use a double click event on the control of the field to be edited.
    Also you might want to create a procedure on some event of your choice, perhaps an on click event for a button that you have created to change records. In order to re-lock the fields so that the user can't edit the field until the unlock button is clicked agian. Other wise once you unlock the control it will stay unlocked until the form is closed. To do this simply use the same code again swapping the true and false.

  3. #3
    Join Date
    Dec 2003
    Location
    Dallas, TX
    Posts
    1,004
    Hi GIJew and "Welcome to the Forum"

    What TMC said is true. I have a database with a form that I set to be not editable when opened, however, the user can select the EditForm CommandButton to make the form editable. After the form is either Saved or Exited the code reverts it back to the non-editable status. Below are three different events I have that accomplish this for me.

    Code:
    #1
    Private Sub Form_Current()  'Set to non-editable status when it opens.
    
        Me.AllowEdits = False       ' Set the form to its read-only state.
        cboStudentID = StudentID      ' Update the Find Record combo box.
        
    End Sub
    Code:
    #2
    Private Sub EditRecord_Click() 'Behind the EditRecord command button.
    
        Me.AllowEdits = True     'jThe form is now editable
        FirstName.SetFocus      ' Move to the FirstName Field
        
    End Sub
    Code:
    #3
    Private Sub Form_AfterUpdate()  'Code for forms AfterUpdate event
    
        Me.AllowEdits = False       ' Return the form to its read-only state.
        MsgBox "This record is now saved."
        
    End Sub
    It works smooth and clean and never know it's there. With CommandButtons on EACH field would be cause for too much and would look crowded as TMC stated. There are other ways I'm sure but this works good for me and have never had a problem.

    hope this offers some kinda help
    have a nice one,
    BUD

  4. #4
    Join Date
    Dec 2004
    Posts
    3
    Thanks for the advice y'all.

    The reason I was putting an edit button per record is because, well, I'm a web programmer = )

    When I'm working on a "web application" I'll throw an edit button next to the record as they are displayed. When user clicks, it allows them to edit that single record.

    I did the single button right now though. It works just fine but it's not easy getting away from the web style of programming.

    Just the same, thank you.

  5. #5
    Join Date
    Dec 2003
    Location
    Dallas, TX
    Posts
    1,004
    Hi GIJew,

    Just glad you found something that would work for you. And as you know, that is what we offer, advice, suggestions, tips. But then, depending on the individual there are sometimes many ways to achieve the same goal. I am familiar with what you are talking about though in the web programming arena and have seen a few forms like that. Now, it wasn't said you just Can't use multiple buttons to do that, just that it would seemingly crowd the form, thereby looking a bit cluttered. However, you can create such buttons and then adjust them to a very small size, looking almost like a small icon. In that case the easiest thing to do from that standpoint would be to create all of the buttons and place them logically as you would in web programming. Then, create a Function that would simply just say to Unlock/Enable that field when the CommandButton is clicked. Though I haven't done so myself, there is a way to create it so that it will somehow read into it just what field you are in when you click it, without having to actually name each field.
    I will look into that for you and see if I can find a way. Unless someone else gets it for you. So hey, don't give up until YOU are totally satisfied with the end results. But also, always keep in mind, IF you are designing something that others/end users will be using, think Logic, Simplistic, or KISS.

    Hope you have a great day,
    BUD

  6. #6
    Join Date
    Dec 2004
    Posts
    3
    I was doing a search for something completely unrelated to this subject and saw that Bud has posted a reply (which I never saw when I posted this message).

    I just wanted to say thank you once again. I always enjoy going to the friendly forums where people try and help one another, giving constructive criticism and not making comments that steer people away from the help they may sorely need.

    In all honesty I wish I could still be programming everything in PHP because that is what I am most comforatable with but now that I've been programming in VBA with all of these neat components I've been enjoying Access quite a bit. In the spirit of enjoying it I've started making an Access db that stores all of the information for my wedding (can't be anal retentive enough sometimes).

    Just the same, thanks.

  7. #7
    Join Date
    Dec 2003
    Location
    Dallas, TX
    Posts
    1,004
    Hi GIJew

    And you're welcome and thanks also for your nice comments. That's what it's all about. If we can help each other then it's a good thing. So you hang in here with us and feel free to jump right in when you have a solution that someone needs. More than one way to skin a cat without getting scratched...hahaha.... (Ouch!!!!!#@$@# freakin cat just ....oh...never mind....LOL)

    have a nice one
    BUD

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •