Link to home
Start Free TrialLog in
Avatar of Patrick O'Dea
Patrick O'DeaFlag for Ireland

asked on

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
Avatar of danishani
danishani
Flag of United States of America image

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
Avatar of DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
 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
     
Avatar of Patrick O'Dea

ASKER

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??
Are all the controls on this form Bound to a field in the Form's Recordsource?

mx
"Are all the controls on this form Bound to a field in the Form's Recordsource?"

Yes I believe so
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
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 ....
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
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?
ASKER CERTIFIED SOLUTION
Avatar of DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
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
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?
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

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
OK ... didn't see your last post ...  I guess we are getting closer :-)

mx