+ Reply to Thread
Results 1 to 12 of 12

Date in Excel ("30/09/2016") copies incorrectly into Access ("30/05/1905")

  1. #1
    Registered User
    Join Date
    02-05-2014
    Location
    Prague, Czech Republic
    MS-Off Ver
    Excel 2010, Excel 2016
    Posts
    72

    Date in Excel ("30/09/2016") copies incorrectly into Access ("30/05/1905")

    Hello everybody,

    couple of days back I've started coding in Access/VBA environment and I'm coming here for beginner advices.

    At the moment, I'm dealing with the issue, that the date I've got in my Excel database (e.g. "30/09/2016") doesn't copy correctly into my Access database (in this case "30/05/1905").

    Here is the fraction of the code I use:

    First, I determine in what column and row is the date information and store it as a vDate.
    Please Login or Register  to view this content.

    Then, I store the data as a global variable:

    Please Login or Register  to view this content.

    Then I call WriteXLSdata procedure copying the data into Access:

    Please Login or Register  to view this content.
    Would any one of you had the idea, why is the date copying over wrong?

    Thank you very much for any tips!

  2. #2
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Date in Excel ("30/09/2016") copies incorrectly into Access ("30/05/1905")

    Hi,

    The problem is that you are passing 2016-09-30 to the SQL statement, but not enclosing it in either text or date markers (' or # respectively) so the SQL treats it as an expression and calculates 2016 minus 9 minus 30 = 1977. Since Office applications like Excel and Access store dates as the number of days from 31/12/1899, 1977 equates to 30th May 1905.

    You need to either pass an actual date value (don't format it) or amend the INSERT statement to this
    Please Login or Register  to view this content.
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  3. #3
    Registered User
    Join Date
    02-05-2014
    Location
    Prague, Czech Republic
    MS-Off Ver
    Excel 2010, Excel 2016
    Posts
    72

    Re: Date in Excel ("30/09/2016") copies incorrectly into Access ("30/05/1905")

    Thank you very much! It seemed to be working. However, out of a blue, the macro started crashing again. So, I would like to ask you one more question relevant to the same code

    Would you have any idea, why the Match function in the second line of the following code
    Please Login or Register  to view this content.
    results every time in an error statement:


    Method 'Sheets' of object'_Global' failed

  4. #4
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Date in Excel ("30/09/2016") copies incorrectly into Access ("30/05/1905")

    You have not properly qualifyied the Sheets property- you must use either
    Please Login or Register  to view this content.
    or more simply
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    02-05-2014
    Location
    Prague, Czech Republic
    MS-Off Ver
    Excel 2010, Excel 2016
    Posts
    72

    Re: Date in Excel ("30/09/2016") copies incorrectly into Access ("30/05/1905")

    Thank you! It's working now. Hopefully, the very last question:

    Is there any way, how to adjust the code for the possibility of not matching any variable? Because the information in every sheet differs, so that not every column header can be found every time

    Please Login or Register  to view this content.

  6. #6
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Date in Excel ("30/09/2016") copies incorrectly into Access ("30/05/1905")

    Declare sCol as Variant, and then use Application.Match instead, which will return an error value. You can then allow for no match by using IsError thus
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    02-05-2014
    Location
    Prague, Czech Republic
    MS-Off Ver
    Excel 2010, Excel 2016
    Posts
    72

    Re: Date in Excel ("30/09/2016") copies incorrectly into Access ("30/05/1905")

    Thank you, but I seem to be having some issues with this latest adjustment. I keep getting error message saying:

    Compile error:

    Method or data member not found
    Would you know, what I might be doing possibly wrong by chance?


    Please Login or Register  to view this content.
    Last edited by lukelucky; 06-29-2017 at 08:06 AM.

  8. #8
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Date in Excel ("30/09/2016") copies incorrectly into Access ("30/05/1905")

    My apologies, I forgot you were working in Access. Use xlsApp.Match instead of Application.Match.

  9. #9
    Registered User
    Join Date
    02-05-2014
    Location
    Prague, Czech Republic
    MS-Off Ver
    Excel 2010, Excel 2016
    Posts
    72

    Re: Date in Excel ("30/09/2016") copies incorrectly into Access ("30/05/1905")

    which is part of this code:

    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    02-05-2014
    Location
    Prague, Czech Republic
    MS-Off Ver
    Excel 2010, Excel 2016
    Posts
    72

    Re: Date in Excel ("30/09/2016") copies incorrectly into Access ("30/05/1905")

    Thank you again for pushing me towards my goal! However, this code is stating type mismatch later on:

    Please Login or Register  to view this content.

    which is part of this code:

    Please Login or Register  to view this content.
    Last edited by lukelucky; 06-29-2017 at 10:16 AM.

  11. #11
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Date in Excel ("30/09/2016") copies incorrectly into Access ("30/05/1905")

    I can't really comment on that since it is not related to anything that has changed in this thread, and I don't have your data.

  12. #12
    Registered User
    Join Date
    02-05-2014
    Location
    Prague, Czech Republic
    MS-Off Ver
    Excel 2010, Excel 2016
    Posts
    72

    Re: Date in Excel ("30/09/2016") copies incorrectly into Access ("30/05/1905")

    Thanks for the answer. My code is working fine at the moment. The problem as I see it was, that the global variable was missing the values for vCurrency. So, I've used this trick to reference it to the blank columns (Column # = 100) if error occured. It's not very clean way, how to do it, but I needed to find the solution fast

    If you had some other better solution, I would be happy if you typed it here.


    Please Login or Register  to view this content.
    Anyway, thanks for your advices yesterday!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 5
    Last Post: 02-05-2019, 12:03 AM
  2. [SOLVED] Column X-Ref list - Sheet1 Col A "pages", Col B:FL "Req" to Sheet2 ColA "req", ColB "page"
    By excel-card-pulled in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 04-07-2017, 09:30 AM
  3. Replies: 1
    Last Post: 01-22-2016, 09:21 AM
  4. VLOOKUP not working for sheet 1 called "2016" in "Jobs.xlsx"
    By A2G in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 01-19-2016, 11:53 AM
  5. [SOLVED] Code that copies row of data to another sheet based on text "Complete"/"Delete"
    By Dremzy in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 04-20-2014, 05:51 PM
  6. Replies: 2
    Last Post: 04-20-2014, 11:18 AM
  7. Replies: 4
    Last Post: 11-17-2013, 12:05 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1