Patrick O'Dea
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
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
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
If <SomeCondition> = True Then ' or False
Me.AllowEdits = True ' or False
Else
Me.AllowEdits = False ' Or True
End If
End Sub
mx
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??
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
mx
ASKER
"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
Upload the db if you can, explain how to reproduce the issue.
mx
ASKER
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 ....
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
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
ASKER
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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
ASKER
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
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?
ASKER
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!
(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)
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
mx
oops ... image attached
Capture1.gif
Capture1.gif
OK ... didn't see your last post ... I guess we are getting closer :-)
mx
mx
Open in new window
Hope that helps,
Daniel