Disallowing edits

New2VB

Registered User.
Local time
Today, 04:41
Joined
Jun 9, 2010
Messages
131
Hi All

Could anyboby tell me how to disallow edits and still have an OnClick value event...


I have a form which has a date field which when "OnClicked" auto-populates with the current date whether intentional or accidental.

I have tried disallowing edits in the form properties and this code...

if not isnull(me!id.value) then
Me.AllowEdits = false
end if

but the field still auto-pupoluates. Is there a way to retain the OnClick and disable editing?

Thanks for your time.
 
Is there code in the On Click or Got Focus of the Date field that populates the field with the date, if so remove the code?
 
If AllowEdits = True then


Else

End If
 
Hi and thanks for the quick replies,

PoppaS - I would like to keep the OnClick code if possible, there are are numerous records that require updating on a daily basis and having auto-populated fields saves quite a bit of time

DCrake - Sorry, I don't understand. My current code reads:
If Not IsNull(Me.Date1, Me.Date2) Then
Me.AllowEdits = False

Do you mean I should disallow editing in the form properties and then code:

If AllowEdits =True Then
Me.Date1=Date, Me.Date2=Date

and rely on Allow Additions in the form properties?
 
That's code to turn on and off Allow Edits. It changes the value of the form's Allow Edits property.
 
If Not IsNull(Me.Date1, Me.Date2) Then

you cannot do this...

If Not IsNull(Me.Date1) AND Not IsNull(Me.Date2) Then

.....
 
Hi,

vbaInet - Is this different to setting the "AllowEdits" to No

DCrake- so my OnLoad form code should be "AllowEdits = False" and my Date1 field OnClick event should be "If IsNull Then Date1 = Date Else AllowEdits=False"

sorry if I'm being dense but I am trying to learn on-the-fly.
 
Hi,

vbaInet - Is this different to setting the "AllowEdits" to No
It's not different, you're simply doing it in code. If you want to set the property from the property sheet that's fine too.
 
It seems DCrake is unavailable to answer your question. What you need is not AllowEdits. All you do is set the LOCKED property of the textbox to YES. The click event will still fire but the user will not be able to change the date.
 
Hi vbaInet,

I've tried that. My form is Allow Edits...No, Both textboxes are locked...Yes but if I click on a field it changes the date???
 
I thought you didn't want manual edits to the date? In what scenario should the code (i.e. On Click event) not run?
 
The scenario I am trying to achieve is something like this:-

Private Sub Date1_Click()
If Me.Date1 = Null Then
Me.Date1 = Date
Else:(AllowEdits=False???)
End If
End Sub

in other words..if a date already exists then it cannot be edited, however a date can be added where none exists if that field is clicked on.
 
A far easy solution is to do this on the after update event of the date text box

Code:
If Me.Date1.Value <> Me.Date1.OldValue Then
   Msgbox "You cannot revise this date once it has been set."
   Me.Date1.Value = Me.Date1.OldValue
End If

The AllowEdits property only refers to keypresses, however you can still change values even if it is set to false. Likewise you can revise a textbox if the control is locked and/or disabled using vba.
 
DCrake, that works but it still doesn't allow the OnClick Date1=Date event. Am I asking for too much?
 
I think you are trying to be to clever, if I may say so, for example lets say as the user I click into the date field by mistake and your code enters today's date into that field, as you expct it to do. How would I undo that if you have another rule that says once a date has been entered into this field it cannot be changed.

You have to think about all senarios. You may not think that this will not happen but beleive me it will, and it will happen the first time someone uses it. I believe you are attempting to overkill it with invention.
 
Apologies for the duplicate threads...sincerely.

What I am trying to do is base the EditsAllowed=True value around an isNull value so that if a record is null it will allow edit/add if it already has a value then editing is disallowed.

If it can't be done or Access has this constraint then so be it, I will have to choose between allowing the OnClick Date1=Date or to remove the code and enter the date manually. I struggle to believe that such a True/False (If Then Else) situation was not built into a database Front-End.

I can see no logical reason (and I am not a logical thinker) why this code does not produce the desired result:-

If Me.Date1.OldValue <> Me.Date1.OldValue Then
Me.Date1 = Date
Else: Me.Date1.OldValue = Me.Date1.OldValue

or even:-

If Me.Date1 = Null then
Me.Date1=Date
Else: Me.Date1=Me.Date1.OldValue

which will disallow changes without messageboxes.

Surely it can't be that hard?
 
Are you looking at what you are typing?

If Me.Date1.OldValue <> Me.Date1.OldValue Then
Me.Date1 = Date
Else: Me.Date1.OldValue = Me.Date1.OldValue

yuo are saying If a <> A then

Else
If A = A

you are comaring the same values each time
 
Whoops, too much cutting & pasting from different notepad sections...

What I meant was...

Private Sub Date1_Click()
If Me.Date1 = Null Then
Me.Date1 = Date
Else: Me.Date1 = Me.Date1.OldValue
End If
End Sub

I am not a VB coder by any stretch of the imagination and I appreciate your patience. The way I read the above code is this-

If Date1 is null then when clicked Date1 = today
If Date1 is not null then keep the existing value

Am I being a dunce or where am I going wrong?
 
You logic is correct, however I refer to my ealier post regarding assurity that the date is required.
 
AAAAAAAAAAARRRRRRRRRRRRRRRRRRGGGGGGGGGGGGGHHHH!!!!!!!!

OK, so I'm a dunce...

Private Sub Date1_Click()
If Me.Date1 <> Date Then
MsgBox "!!!!"
Else: Me.Date1 = Date
End If
End Sub

Who needs disabled edits???????

Thanks to all who helped.
 

Users who are viewing this thread

Back
Top Bottom