Results 1 to 3 of 3
  1. #1
    MrBologna is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Sep 2018
    Posts
    48

    Dates inserted into a table are not coming in properly

    I have a form where the user inputs two days, the start and end dates for vacation time. These text boxes are formatted for short date, and the date picker was used for this test (though I want it to work when manually entered as well)



    I am trying to put these dates into the Vacation_Time table, but they come in as shown in the picture below (12/30/1899 and they show a timestamp if i target the value in the table) even though they are data type DATE across the board.

    Click image for larger version. 

Name:	tblVacationTime.JPG 
Views:	7 
Size:	17.0 KB 
ID:	38549

    The messagebox popup (see picture attachment below) shows what is calculated for each value. Maybe it's because I have it formatted as a short date?
    I suppose I could just store them as text, since the only thing I would use them for is to calculate days of vacation which is already working as intended.

    Click image for larger version. 

Name:	popupCalcValues.JPG 
Views:	7 
Size:	26.6 KB 
ID:	38550

    I must be missing something, here is my code:

    Code:
    Dim Employee_ID_Temp As IntegerDim Employee_Name As String
    Dim Vacation_Start As Date
    Dim Vacation_End As Date
    Dim Vacation_Days_Calculated As Integer
    
    
    Employee_Name = Me.txtVacation_Employee.Value
    Employee_ID_Temp = Me.txtVacation_Employee_ID.Value
    Vacation_Start = Me.txtVacation_Start.Value
    Vacation_End = Me.txtVacation_End.Value
    
    
    Vacation_Days_Calculated = WorkdayDiff(Vacation_Start, Vacation_End)
    
    
    MsgBox ("Vacation Days Used: " & Vacation_Days_Calculated & " Start Date: " & Vacation_Start & " End Date: " & Vacation_End)
    
    
    strSQL = "INSERT INTO Vacation_Time ( Employee_ID, Start_Date, End_Date, Vacation_Days_Used ) VALUES (" & Employee_ID_Temp & ", " & Vacation_Start & ", " & Vacation_End & ", " & Vacation_Days_Calculated & ");"
    
    
    DoCmd.RunSQL (strSQL)

  2. #2
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    you have to encapsulate dates in # marks

    ...& Employee_ID_Temp & ",#" & vacation_start & "#,#" & vacation_end & "#, " ....

  3. #3
    MrBologna is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Sep 2018
    Posts
    48
    Aha! it was so simple! thank you

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

Similar Threads

  1. Date changes format when inserted into table.
    By todmac in forum Programming
    Replies: 3
    Last Post: 07-08-2016, 11:12 AM
  2. Replies: 3
    Last Post: 06-22-2016, 02:15 PM
  3. Replies: 5
    Last Post: 01-23-2015, 03:38 PM
  4. Replies: 5
    Last Post: 07-12-2014, 02:55 PM
  5. text box expression inserted to table
    By normie in forum Access
    Replies: 3
    Last Post: 03-13-2012, 04:14 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