Results 1 to 5 of 5
  1. #1
    mainerain is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Sep 2018
    Location
    Maine, USA
    Posts
    146

    vba for changing AllowEdits on all Forms

    I want to have other people view my database without them being able to make edits to the data in any of my many forms. I was thinking of using a particular key stroke to AllowEdits for all forms. Is there a generic code to change all forms without having to name each form in the code to allow/disallow edits? Thanks

  2. #2
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,397
    Is there a generic code to change all forms without having to name each form in the code to allow/disallow edits?
    No. assuming you have a login process you can set a global 'EditingAllowed' boolean variable to true or false depending on the user 'rights'. Then in each form open event you can call a function to set the allowedits property in the form. You do not need to have code in each form, just call the function from the property. e.g.

    put this in a standard module

    Function fnAllowEdits(frm as Form)

    frm.allowedits=gblEditingAllowed

    End Function
    then for each form open event property, instead of [Event Procedure] put

    =fnAllowEdits([FORM])

    Goes without saying that you have split the db and each user will have their own copy of the front end on their local machine so their global variable will only relate to them



  3. #3
    apr pillai's Avatar
    apr pillai is offline Competent Performer
    Windows 10 Access 2007
    Join Date
    May 2010
    Location
    Alappuzha, India
    Posts
    209
    Try this:
    Code:
    Public Function NoEdits()
    Dim ctr As Container, doc As Document
    Dim db As Database, strForm As String
    
    
    Set db = CurrentDb
    Set ctr = db.Containers("Forms")
    For Each doc In db.Containers("Forms").Documents
        strForm = doc.Name
       DoCmd.OpenForm strForm, acDesign, , , , acHidden
       Forms(strForm).Properties("AllowEdits") = False
       DoCmd.Close acForm, strForm, acSaveYes
    Next
    End Function

  4. #4
    Raddle is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Sep 2021
    Posts
    60
    I know this is old but thank you for this. Exactly what I needed !

  5. #5
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2013 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,101
    @Raddle: just a quick thing to mention, setting AllowEdits = False will disable any unbound controls (usually combos) used for searching\navigating to certain records. A better alternative is to set the form's recordset type to 2 (=Snapshot).
    https://learn.microsoft.com/en-us/of....recordsettype
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

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

Similar Threads

  1. AllowEdits and Subforms
    By fret hack in forum Forms
    Replies: 2
    Last Post: 10-16-2017, 09:39 AM
  2. Changing Fonts on the fly in Forms
    By pharrison74 in forum Forms
    Replies: 2
    Last Post: 03-23-2016, 03:04 PM
  3. .allowEdits property
    By Lukael in forum Access
    Replies: 3
    Last Post: 11-23-2015, 12:49 AM
  4. Allowedits according to the record
    By lios1984 in forum Forms
    Replies: 4
    Last Post: 06-20-2012, 11:41 PM
  5. AllowEdits in Subform
    By Jackie in forum Forms
    Replies: 3
    Last Post: 03-02-2011, 10:51 AM

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