Solved

acFormEdit Not applying

Posted on 2014-01-27
4
518 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 34

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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

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…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

895 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

12 Experts available now in Live!

Get 1:1 Help Now