Solved

acFormEdit Not applying

Posted on 2014-01-27
4
525 Views
Last Modified: 2014-01-28
Hello,

I am currently having issues when using the acFormEdit when opening a form with VBA. The issue is I open a "view/edit" form from another form (on click event). I have set it to open in acFormView mode which works perfectly fine. On that form I then have an "Edit" button which is then supposed to open the same form in acFormEdit mode but when I try to edit the data within the fields I can't. it behaves as if it is still in acFormView but the code runs fine. Here is what Iam using:

DoCmd.OpenForm "Frm_Edit_ViewTrainingRecords", acNormal, , "Autonumber = " & Me.Autonumber, acFormEdit, acWindowNormal

not really sure why this is happening. The form properties are set to edit as default. And i just figured i would control the editing using form open and on click events.

Thanks for any help you can offer.
0
Comment
Question by:mickferrari
  • 2
4 Comments
 
LVL 84
ID: 39814484
On that form I then have an "Edit" button which is then supposed to open the same form in acFormEdit mode
Instead of doing that, why not just toggle the AllowEdits property of that form.

Set AllowEdits to No in the form's Design view.

Open the form normally:

DoCmd.OpenForm "Frm_Edit_ViewTrainingRecords", acNormal, , "Autonumber = " & Me.Autonumber

Now when the user clicks your Edit button, do this:

Me.AllowEdits = True

That will put your form into 'edit" mode.
0
 
LVL 35

Accepted Solution

by:
PatHartman earned 500 total points
ID: 39815731
Unfortunately, when you set AllowEdits to False, it also disables the click events of your buttons.  So, I use a little sub to lock/unlock all the controls of a form.  Put this sub in a standard module so you can call it from any form.  It takes a form object as input and a Boolean to specify whether you want to lock or unlock the controls.  To isolate the controls you want to continue to work even when the others are locked, set their Tag property to "NoLock".  Don't forget to call this sub from your subforms also.

Put one of these call statements in the CURRENT event of each form where you want to lock/unlock the controls.
Call LockControls(Me, True)

Open in new window

or
Call LockControls(Me, False)

Open in new window


In my case, I have some flags that are on the login form that I use:
    If Forms!frmLogin!chkOKCLI = True Then
        Call LockControls(Me, False)        'unlock
    Else
        Call LockControls(Me, True)         'lock
    End If

Open in new window

You could also do this with a button or option group to have the user manually lock/unlock a form for editing.
Public Sub LockControls(frm As Form, bLock as Boolean)
    Dim ctl As Control
    For Each ctl In frm.Controls
    Select Case ctl.ControlType
        Case acTextBox, acComboBox, acListBox, acCheckBox
            If ctl.Tag = "NoLock" Then
                ctl.Locked = False
            Else
                ctl.Locked = bLock         'toggle locks
            End If
    End Select
Next ctl
Set ctl = Nothing

End Sub

Open in new window

0
 

Author Comment

by:mickferrari
ID: 39816274
Hi PatHartman,

That's a clever solution, and it makes sense that the click events are cancelled.

I set up the sub using the code you supplied and put the "Call LockControls(Me, True)" into the On Current however I get a compile error: Expected variable or procedure, not module.

The sub is a standard module and named correctly so I'm not sure what's wrong.
0
 

Author Comment

by:mickferrari
ID: 39816301
Sorry PatHartman,

Rookie mistake named the module the same as the sub :P caused a bit of conflict.

This works great and gives me a lot of control over what can and can't be edited.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question