Results 1 to 3 of 3
  1. #1
    FruStalin is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Mar 2012
    Posts
    18

    Gettting weird results using date() in vba, help is needed.

    Hello there

    I want to place the current date into af field. The code looks like this:
    Private Sub cmdNew_Click()

    Dim mySQL As String
    Dim day


    day = Date

    mySQL = "INSERT INTO tblAfsluttet( IdJournal, Afslutningsdato)"
    mySQL = mySQL & " Values (" & IdJournal & ", " & Date & ")"

    MsgBox "Today's Date is " & Date

    DoCmd.SetWarnings False


    DoCmd.RunSQL mySQL
    DoCmd.SetWarnings True


    End Sub

    The code puts in a date in the [Afslutningsdato] field all right, but it is 19-07-1894!!! The msgbox which is for verifing the date data shows 25-03-2012, which is the correct one :-).
    The code is working, but the date is really strange!

    The field where the wrong date is put in has the same specification as other date fields which shows the correct date.

    So the question is has any one of you clever access guys had this problem and what was the solution?

    Regards

    Morten

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Try:

    mySQL = mySQL & " Values (" & IdJournal & ", #" & Date & "#)"

    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    FruStalin is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Mar 2012
    Posts
    18
    Nice suggestion June7

    That solve my problems. Thanks alot.

    Regards

    Morten

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 11
    Last Post: 03-21-2012, 12:51 PM
  2. Date Paramater prints weird
    By NOTLguy in forum Reports
    Replies: 9
    Last Post: 10-20-2010, 07:58 AM
  3. Weird Query results
    By UCBFireCenter in forum Queries
    Replies: 0
    Last Post: 10-06-2009, 03:38 PM
  4. Replies: 8
    Last Post: 10-02-2009, 08:03 AM
  5. Get the sum of decimal values - weird results
    By BengtCarlsson in forum Queries
    Replies: 2
    Last Post: 02-10-2006, 04:29 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums