-
Access Date function pain
I am sure this should be easy but it is eluding me. can anyone help?
Private Sub Form_Current()
Dim intnewrec As Integer
intnewrec = Form.NewRecord
If intnewrec = True Then
myDate = date
date is returning Null - it's MS own bloody example for gods Sake!
Thanks in advance,
Andy
-
How do you know that the Date function is returning Null? Did you try executing the function in the immediate window?
Paul
~~~~
Microsoft MVP (Visual Basic)
-
It works for me!
Try putting a break on the line under:
myDate = date
and put your cursor over "mydate" and see what it says. If it still gets you a null, it's because "intnewrec" is not true! (meaning it's not a new record!)
I tried:
Code:
Private Sub Form_Current()
Dim intnewrec As Integer
Dim NewDate As Date
intnewrec = Form.NewRecord
If intnewrec = True Then
NewDate = Date
End If
End Sub
This worked!
L
A balanced diet is a cookie in each hand.
-
Do you have a field called "Date"?
If it is so, you are returning the value of your field, which is Null because you are in a new record.
This is a current mistake. Never name a field Date, Name, Page, Pages or some other word that defaults to something else in the system.
If this is the problem, ask for the date with the following code, which forces VB into using the Date function of VB instead of referencing your own field:
MyDate = VBA.Date
Jacques Bourgeois
JBFI
http://www3.sympatico.ca/jbfi/homeus.htm
-
Date is a keyword. Ya can't use keywords as field names!
A balanced diet is a cookie in each hand.
-
You should not use keywords as fields... but in Access, you can.
Keep in mind that Access was first designed for ease of use. A lot of people create databases in Access without any knowledge of programming. So Microsoft took a few shortcuts in its integrity.
Jacques Bourgeois
JBFI
http://www3.sympatico.ca/jbfi/homeus.htm
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|