• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 352
  • 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 Access MVP)Database ArchitectCommented:
 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
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
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 Access MVP)Database ArchitectCommented:
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 Access MVP)Database ArchitectCommented:
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 Access MVP)Database ArchitectCommented:
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 Access MVP)Database ArchitectCommented:
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 Access MVP)Database ArchitectCommented:
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 Access MVP)Database ArchitectCommented:
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 Access MVP)Database ArchitectCommented:
oops ... image attached
Capture1.gif
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
OK ... didn't see your last post ...  I guess we are getting closer :-)

mx
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

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