• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 347
  • Last Modified:

DIsabling Edits on a FORM

CLick frmCustomers.

I want to code (in VBA) so that this form is not editable.
I have tried this under the Event "OnCurrent" ...  but no joy!
Any code I have put in does NOT prevent editing.

Ultimately, this coding will be based on a "If" statement.
I have tried numerous ways but none have worked.

How do I make this form non-editable via VBA?
KeyYOUTUBE.zip
0
Patrick O'Dea
Asked:
Patrick O'Dea
  • 10
  • 6
1 Solution
 
danishaniCommented:
Try to use the following code in the OnLoad event of your form:

Private Sub Form_Load()
Me.AllowEdits = False
End Sub

Open in new window


Hope that helps,
Daniel
0
 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
 Private Sub Form_Load()

  If <SomeCondition> = True Then ' or False
      Me.AllowEdits = True  ' or False
  Else
      Me.AllowEdits =  False ' Or True
  End If
   
  End Sub

mx
     
0
 
Patrick O'DeaAuthor Commented:
Thanks for both answers.
However, I had tried something similar already.
This simply does NOT work for me.
The form is entirely editable still.
Any thoughts??
0
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
Are all the controls on this form Bound to a field in the Form's Recordsource?

mx
0
 
Patrick O'DeaAuthor Commented:
"Are all the controls on this form Bound to a field in the Form's Recordsource?"

Yes I believe so
0
 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
Well, then something else is going on then.  If AllowEdits = False is not working, are you SURE that there is not some code elsewhere - like the Form Current event - that is resetting this back to True.

Upload the db if you can, explain how to reproduce the issue.

mx
0
 
Patrick O'DeaAuthor Commented:
Thanks mx,

The database was uploaded in my very first post.

My VBA is far from perfect but I cannot see any reason for my problems ....
0
 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
I assume frmCustomers ?

You have this:

Private Sub Form_Current()
 

   On Error GoTo Form_Current_Error
WriteAudit ("Viewed : " & Me.CustomerID & " ->" & Me.CustomerName)
'*************************************
'Me.AllowEdits = False

it's remmed out.
And really, it should be in the Form Load event ...

mx
0
 
Patrick O'DeaAuthor Commented:
it's remmed out.

Yes mx,  I was remmed out.

But it does not work when it is not remmed out.
It does not seem to work in either event??

Any thoughts?
0
 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
What is this:

    If AllowLock = True Then
        MsgBox "This Call has been locked !"
        Me.frmDetail.Enabled = False
        Me.Status.Enabled = False
        Me.Contractor.Enabled = False
        Me.Merchant.Enabled = False
        Me.DateCompleted.Enabled = False
        'Me.OverRidePrice.Enabled = False
       
   End If

I can't find AllowLock ...
Also, noting there are one or more compile errors in your db.

mx
0
 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
ok .. Something in the On Current event is creating this issue, because if I do this::

Private Sub Form_Current()
 Exit Sub ' skip this
'code

Exit Sub

and

Private Sub Form_Load()
    Me.AllowEdits = False
End Sub

Then the Form is not editable ...

mx
0
 
Patrick O'DeaAuthor Commented:
Thanks mx,

There is reasonably good logic for most (not all!) of my code.

I have stripped the code to a minimum and things are now working.

Thanks again for your patience
0
 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
ahh ... did you figure it out ?  I still can't see what's making this happen.  Can't seem to figure out what AllowLock is?
0
 
Patrick O'DeaAuthor Commented:
mx,

(The basic code "Me.AllowEdits = False" is now working because I stripped out lots of other stuff!)


Regarding the AllowLock.`
THE THEORY
=============
See tblStatus which has a field AllowLock.
If the "Customer" has a "tblStatus.AllowLock = True" then the some fields will be locked.
This actually works but I confess , on reviewing the code, I am not sure 100% why !
I will review later
See code attached.

It's 1:30 a.m. here and time to retire.  (It may look better in the morning).

Thanks again for your interest and assistance!

Private Sub Status_Change()
On Error GoTo Status_Change_Error
Dim LockLookup As String
Dim strSQL As String
LockLookup = DLookup("allowlock", "tblstatus", "statusid=" & Status.Value)

Open in new window

0
 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
OK ... I found AllowLock ... it's a field in qryCustomer and in table tblStatus. So ... this is apparently causing the issue ... some how resulting in the AllowEdits=False to be overridden ...?

mx
0
 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
oops ... image attached
Capture1.gif
0
 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
OK ... didn't see your last post ...  I guess we are getting closer :-)

mx
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 10
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now