Solved

acFormEdit Not applying

Posted on 2014-01-27
4
511 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
Comment Utility
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 34

Accepted Solution

by:
PatHartman earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

763 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now