access - can't empty a field

TravelingCat

Registered User.
Local time
Today, 20:14
Joined
Feb 22, 2010
Messages
42
Hi,
I'm checking whether the date entered on my form is friday or saturday, and if it is, a message pops out. But in addition to that, i want this field to empty, so the user can enter a correct date (that would be a working day).
I tried all these:
eventDueDate/eventDueDate.Value = "", nothing, null.... i get this error:
"The macro or function set to the BeforeUpdate or ValidationRule property for this field is preventing Microsoft Access from saving the data in the field"
And yes, the code is sitting in the eventDueDate_beforeUpdate event.
What might be the solution for this?
Thanks
 
What does your actual code look like?
Me.DateField = "" should suffice
 
It looks like this:
Code:
Private Sub eventDueDate_BeforeUpdate(Cancel As Integer)
    If Weekday(eventDueDate.Value, vbSunday) = 6 Or
        Weekday(eventDueDate.Value, vbSunday) = 7 Then
        MsgBox "You chose friday/saturday, plz choose another date"
        Me.eventDueDate = "" [COLOR=blue]- it doesn't work, the same error[/COLOR]
    End If
.....
 
Hi,

You'll need to cancel the update by setting Cancel = True. You are emptying your eventDueDate field which is possibly mandatory in your table, the reason for your error.

HTH,

Simon B.
 
Hi Simon, i entered "Cancel = True" inside the code, right after the MsgBox, and then tried the "eventDueDate = "" ", but still the same error pops up.. or maybe you meant something else?
 
Hi,

Is you eventDueDate linked to a field in a table? If so, check what is the field type and if it accepts null values and empty strings.

Simon B.
 
Me.eventDueDate = ""

this is the culprit - you cant do this inside the event handler

try this

Code:
Private Sub eventDueDate_BeforeUpdate(Cancel As Integer)
    If Weekday(eventDueDate.Value, vbSunday) = 6 Or
        Weekday(eventDueDate.Value, vbSunday) = 7 Then
        MsgBox "You chose friday/saturday, plz choose another date"
[COLOR="Red"]        cancel = true
        docmd.sendkeys "{esc}"
        exit sub
[/COLOR]
    End If

note that the use of sendkeys is deprecated/not recommended

the equivalent is something like

docmd.undo or
runcommand accmdundo

I am not sure of the recommended syntax.
 

Users who are viewing this thread

Back
Top Bottom