How do i clear value in a single field?

xwnoob

Registered User.
Local time
Today, 00:04
Joined
Nov 7, 2011
Messages
70
Ok, so here is my code for the validation of my form :

Private Sub AvailablePeriodEnd_BeforeUpdate(Cancel As Integer)
If [AvailablePeriodStart] > [AvailablePeriodEnd] Then
MsgBox ("You have entered a date wrongly")
Me!AvailablePeriodEnd = ""
End If
End Sub

However the code in red gives me an error everytime. How do i replace this code with a code that resets the value in the AvailablePeriodEnd field? I just want the field to be blank/reset value if the user enters a date that is less than the start date.
 
I'm imagining the error you are getting is;
attachment.php


Use the following code;
Code:
Private Sub AvailablePeriodEnd_BeforeUpdate(Cancel As Integer)
If [AvailablePeriodStart] > [AvailablePeriodEnd] Then
     MsgBox ("You have entered a date wrongly")
     Cancel = True
     Me.AvailablePeriodEnd.Undo
End If
End Sub
 

Attachments

  • Error.JPG
    Error.JPG
    15.3 KB · Views: 333
Thanks your code solved the error part. However, it did not work the way as i thought i would. The code only cleared the last number of the year if it was earlier that the start date but i want to clear everything in the field. Also, subsequent times that i entered an earlier date on purpose resulted only in access displaying a error without removing the last number of the year. It just gave a message and then everything remained.

Is there anyway the code can be improved?
 
Can you post a copy of your DB? ('07 or earlier) and I'll take a look.
 
Sure. Its the AddCommitmentDetails form.
Also, do you happen to know a method to expand columns in a listbox. I have a field,borrowertitle, that can get really long sometimes and the listbox doesnt have an option to expand. Help on that would be appreciated
 

Attachments

You missed the;
Code:
Cancel = True
portion of the code in your DB.


As for the List box column thing let me do some research.
 
Oh yea i missed out the cancel. Thanks it worked
 

Users who are viewing this thread

Back
Top Bottom