BeforeUpdate(Cancel As Integer) - Question

netman

New member
Local time
Today, 01:42
Joined
Aug 2, 2007
Messages
6
Hello,

I'm trying to get the BeforeUpdate(Cancel As Integer) to work for me.

I have got it to work with Me.Date2 = Now()

But I do not want the Date and Time, just the date.

If I try Me.Date2 = Date

Nothing seems to work.

Any ideas, I do not know if there is another command that I can use or not.

Thanks,

Ranger
 
Try using Date(). The parentheses seem to help Access to know what you mean
 
The parentheses seem to help Access to know what you mean

It's an unforunate thing that Access behaves inconsistently with this; in some fields (I think in properties window), if you enter "Date()" (or any other functions), it changes to "Date", whereas "Date()" works better in VBA.

It's usually best to always enter () for any functions, even if Access omits the () from the field you entered it in.
 
Just as an FYI -

You need the () when entering the Date or Now function in a control source or a query, but you don't need it when entering in VBA, except in a few circumstances. So, as Banana has mentioned, you can type it in anywhere and Access will exclude it, or squawk at you, if it doesn't need it.
 
I tryied it with just Date () and it removed (), as you said, but the date does not get put into the field.

Is there any other thing, that I need to do, to make it work?
 
What happens when you go to the immediate window and key in:
?Date()
Have you named some procedure in your application "Date"?
 
Private Sub Form_BeforeUpdate(Cancel As Integer)
Me!Date = Date
End Sub

I do not understand immediate windows, is that the field?
 
Me!Date = Date

This is your problem. Your field is using a reserved name "Date", which is confusing Access (which do you want? the field or the function?). Rename your field to something else (say, StartDate) then it should work.
 
I'll bet Access is getting confused because you have named your field or control "Date" which is a reserved word. As for the immediate window, while looking at your code type <CTRL> G and the immediate window will open at the bottom of the screen.
 
I am a bit confused because in the first code example the field was called Me!date2 which should have been OK. When did it change to Date thus causing more problems.
 
Thanks to everyone. That did it.

I now have a new problem that I created. I'll post it on the main forum.

Thanks,

Ranger
 

Users who are viewing this thread

Back
Top Bottom