?
Solved

acFormEdit Not applying

Posted on 2014-01-27
4
Medium Priority
?
543 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 85
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 38

Accepted Solution

by:
PatHartman earned 2000 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

765 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