Results 1 to 8 of 8
  1. #1
    harryklein is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Aug 2018
    Posts
    48

    Importing entire sheet from excel via VBA

    Hi,

    I use vba code to import the content of a sheet into a table.
    The sql looks something like this

    Code:
    INSERT INTO Table1(Field1, myDate) SELECT(Field1, DateField) FROM  [Excel 12.0 Xml;HDR=Yes;Database=C:\Users\MYFILE.xlsb].[DATA$]
    The format of mydate-field in Table1 is date. It worked fine till the last times, when the data in the DateField in excel has changed, the has been extended with some character that is not the part of the date. It is like "20210339ABC". The lenght is fixed. The import didn't stop, but myDate field in the table remains empty.

    I would like to use some formatting-function or serialdate to get the right date in my table, but I couldn't figure out, what would be right way.
    Any help would be appreciated.


    Thank you

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,911
    I cannot see how the numeric portion is a date.?
    What did it look like before?

    20210339 ?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,405
    In Excel, try saving the file as xlsx, then changing your sql accordingly.

  4. #4
    harryklein is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Aug 2018
    Posts
    48
    It isn't, it is a typo.
    The correct value is 20210329, and it was put into excel like this.

  5. #5
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,114
    I'd say you should use a temporary (staging) table with the second field set as Short Text instead of date then use a query to move the imported data to the final table using a Left([tempTable1].[MyDateString],6).

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  6. #6
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,911
    Quote Originally Posted by harryklein View Post
    It isn't, it is a typo.
    The correct value is 20210329, and it was put into excel like this.
    Well you could do it using DateSerial()
    Code:
    tt="20210329ABC"
    ? dateserial(left(tt,4),mid(tt,5,2),mid(tt,7,2))
    29/03/2021
    but that would expect correct data?, so Vlad's suggestion of a staging table would be better I believe.

    What are you meant to do when the date is rubbish?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  7. #7
    harryklein is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Aug 2018
    Posts
    48
    you mean, when the data in this field cannot be interpreted as a date? it didn't happen so far and no instructions are there for this scenario.
    Thanks a lot for your answer.

  8. #8
    harryklein is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Aug 2018
    Posts
    48
    Thanks for the answer, Vlad.

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

Similar Threads

  1. Replies: 4
    Last Post: 10-29-2020, 02:01 AM
  2. Trouble importing Excel sheet - Access doesnt see it.
    By knowshowrosegrows in forum Access
    Replies: 2
    Last Post: 08-31-2015, 12:55 PM
  3. Tons of issues importing excel sheet for leads
    By udfxrookie in forum Import/Export Data
    Replies: 2
    Last Post: 02-07-2015, 08:54 AM
  4. Importing full excel sheet to access
    By karakal in forum Import/Export Data
    Replies: 0
    Last Post: 03-22-2010, 03:48 PM
  5. Importing Excel Sheet into Access dbase
    By tonystowe in forum Import/Export Data
    Replies: 0
    Last Post: 12-08-2006, 11:35 AM

Tags for this Thread

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