Access Date function pain


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 6 of 6

Thread: Access Date function pain

  1. #1
    Join Date
    Aug 2004
    Posts
    6

    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
    Andy Seabrook
    One of the virtually energetic!
    www.virtualenergygroup.co.uk
    www.blueorchidbride.com
    www.landraiders.com

  2. #2
    Join Date
    Dec 2003
    Posts
    2,750
    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)

  3. #3
    Join Date
    Jun 2004
    Location
    Houston area
    Posts
    557
    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.

  4. #4
    Join Date
    Feb 2004
    Location
    Longueuil, Québec
    Posts
    577
    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

  5. #5
    Join Date
    Jun 2004
    Location
    Houston area
    Posts
    557
    Date is a keyword. Ya can't use keywords as field names!
    A balanced diet is a cookie in each hand.

  6. #6
    Join Date
    Feb 2004
    Location
    Longueuil, Québec
    Posts
    577
    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
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center