Results 1 to 12 of 12
  1. #1
    banpreet is offline Competent Performer
    Windows 8 Access 2010 64bit
    Join Date
    Jul 2016
    Posts
    117

    Form Status Enable or Lock Form


    Hey guys,

    I have a form and at the end of there is a drop down with three options:
    draft
    pending
    Final

    Initially the combo box default value is draft which allows users to edit it their forms. How do I make it when the user clicks pending or final, both the options will lock the whole form, so no edits can be made.

    Thanks, all help will be appreciated!

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,521
    Have a LockForm sub, then run it for 2 events: cboStatus AFTERUPDATE, and me.Oncurrent when the record changes.....
    Code:
    sub LockForm()
    me.locked= cboStatus<>"Draft"
    end sub
    
    sub form_onCurrent()
    LockForm
    end sub
    
    sub cboStatus_afterupdate()
    LockForm
    end sub

  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,016
    Does Access 2010 really support a Locked Property for Forms? It's doesn't exist through v2007, and isn't mentioned in any 'new features' articles I've seen, for v2010. Of course, the Boys of Redmond are not known for documenting changes that they make!

    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
    sdel_nevo is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2013
    Location
    Gloucester, UK
    Posts
    402
    Hi Banpreet

    what I have done is on the after update event of the cbobox put this code

    IF cbotextbox = "pending" or cbotextbox = "Final" then
    Forms("yourformname").AllowAdditions = False
    Forms("yourformname").AllowDeletions = False
    Forms("frmCustomersEditOrders").AllowEdits = False
    end if

    I have also put this on the forms on load event so that when the form opens up the form is locked as required

    hope this helps

    Steve

  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,016
    First off, I assume that the use of both yourformname and frmCustomersEditOrders is a typo, I'll stick with yourformname.

    Don't want this in the Form_Load event, as the Form will be Locked or not Locked, for all Records, depending on the value of cbotextbox in the first displayed Record!

    Instead, in order for the formatting to be Record-appropriate, in the OnCurrent event, you need to use this:

    Code:
    Private Sub Form_Current()
     
     If Me.cbotextbox = "pending" Or Me.cbotextbox = "Final" Then
        Forms("yourformname").AllowAdditions = False
        Forms("yourformname").AllowDeletions = False
        Forms("yourformname").AllowEdits = False
     Else
        Forms("yourformname").AllowAdditions = True
        Forms("yourformname").AllowDeletions = True
        Forms("yourformname").AllowEdits = True
     End If
    
    End Sub

    And since this code concerns the Form you're putting the code in, Forms("yourformname") can be replaced with the shortcut Me...which refers to the current Form...so:

    Code:
    Private Sub Form_Current()
     
     If Me.cbotextbox = "pending" Or Me.cbotextbox = "Final" Then
        Me.AllowAdditions = False
        Me.AllowDeletions = False
        Me.AllowEdits = False
     Else
        Me.AllowAdditions = True
        Me.AllowDeletions = True
        Me.AllowEdits = True
     End If
    
    End Sub

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

    All posts/responses based on Access 2003/2007

  6. #6
    sdel_nevo is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2013
    Location
    Gloucester, UK
    Posts
    402
    Hi MissingLinq

    yeah was a typo, forgot about the me.

    steve

  7. #7
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    That code will work, but with one big caveat:

    Once you set the status value to "Pending or "Final", there is no going back if you forgot to make a change before setting the status. Once you set AllowEdits to false, you can't change it back to "draft".

    Maybe you could put an unbound "Reset" button on the form to recover from an "Oops!"

  8. #8
    sdel_nevo is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2013
    Location
    Gloucester, UK
    Posts
    402
    Hi john

    good point lol, never thought about that
    good catch

    steve

  9. #9
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,016
    That's a good point! It only applies, of course, if you actually leave the Record and then you realize you've forgotten something or entered something incorrectly.

    There's really no point in doing this in the AfterUpdate event of the Combobox...as long as you're still on the Record, you can edit it...and having the code in the Form_Current event will prevent this when returning to the Record.

    Quote Originally Posted by John_G View Post

    ...Maybe you could put an unbound "Reset" button on the form...
    When I need to do that, usually when someone in authority needs to make the change, I use the DoubleClick event of a Label (frequently the Form title Label) on the Form to make it editable, again. It's easy to do, without being observed, and the average user has no idea that Clicking or DoubleClicking on a Label can do anything!

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

    All posts/responses based on Access 2003/2007

  10. #10
    banpreet is offline Competent Performer
    Windows 8 Access 2010 64bit
    Join Date
    Jul 2016
    Posts
    117
    Hey Missinglinq, how do I do this, can you post the code, that would be really helpful?

    Thanks!

  11. #11
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,016
    Just replace YourLabelName with the actual name of your Label:

    Code:
    Private Sub YourLabelName_DblClick(Cancel As Integer)
      Me.AllowEdits = True
    End Sub
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  12. #12
    banpreet is offline Competent Performer
    Windows 8 Access 2010 64bit
    Join Date
    Jul 2016
    Posts
    117
    I ran into a problem,

    I have to state that I have three of the same forms but with different stuff because of an approval process of the forms. The first form is to the customer then gets sent to the approver, who opens up the same form but now how a box to approve then gets send to another approver who sees the same form but with a different subform the sign. On the first form, for the customer the drop down is locked by the user, but when it goes first approver, he has access to the drop down and he will switch to pending. I want it that after he hits pending, it will lock the form for the customer, will this require the same code, or is to complex it won't work, or is there any other code. And then after that the third firm, the second approver will switch the drop down to final, so final for the last form and pending for the second form will both lock the first form so there can be no edits.

    Thanks!

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

Similar Threads

  1. Move status bar to top of form
    By fat_ankles in forum Forms
    Replies: 6
    Last Post: 12-18-2015, 09:44 PM
  2. Replies: 13
    Last Post: 11-11-2014, 02:43 PM
  3. Need help with code to enable autopopulation of form
    By bacarley in forum Programming
    Replies: 1
    Last Post: 11-29-2011, 11:54 PM
  4. Replies: 1
    Last Post: 07-18-2011, 03:08 AM
  5. Progress/Status Bar on Form
    By Tomfernandez1 in forum Forms
    Replies: 5
    Last Post: 05-10-2011, 04:41 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