Solved

acFormEdit Not applying

Posted on 2014-01-27
4
529 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 36

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
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.

696 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