473,395 Members | 1,678 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Importing Dates from Excel

I'm trying to import data from Excel into an Access table using VBA. I can't do the Import file because the dates on the spreadsheet are convaluted. Hence, my dilemma. When viewing the spreadsheet, some of the dates in the column are formatted as mm/dd/yy h:mm (10/1/2007 0:00) and when I actually click on the cell it shows mm/dd/yyyy hh:mm:ss AM/PM (10/1/2007 12:00:00 AM). I have tried changing the entire column using
Expand|Select|Wrap|Line Numbers
  1. Columns("G:G").Select
  2. selection.numberformat = "MM/DD/YYYY"  
and
Expand|Select|Wrap|Line Numbers
  1. Columns("G:G").Select
  2. selection.numberformat = "mm/dd/yyyy hh:mm"
and tried to format as the following upon rst.addnew
Expand|Select|Wrap|Line Numbers
  1.  If Not IsNull(RST2![AR Initial Contact Date]) Or RST2![AR Initial Contact Date] <> "" Then
  2. rst![AR Initial Contact Date] = Format(RST2![AR Initial Contact Date], "mm/dd/yyyy")
  3. Else
  4. End If
It will change some but not all. It seems to pull in those that are originally formatted as mm/dd/yy h:mm but not mm/dd/yyyy hh:mm:ss AM/PM.

AR Initial Contact field datatype is date/time and format is short date.
Any ideas or suggestions?

Thanks
Nov 13 '07 #1
3 1762
MMcCarthy
14,534 Expert Mod 8TB
Try creating a variable to temporarily store the value and try formatting it as a long date as this is handled better by Access. You can still have the format of the field in rst set to short date.

Expand|Select|Wrap|Line Numbers
  1.  
  2. Dim tmpDate as Date
  3.  
  4.     If nz(RST2![AR Initial Contact Date], "") <> "" Then
  5.         tmpDate = Format(RST2![AR Initial Contact Date], "dd mmm yyyy")
  6.     Else
  7.         tmpDate = ""
  8.     End If
  9.     rst![AR Initial Contact Date] = tmpDate
  10.  
Nov 14 '07 #2
Try creating a variable to temporarily store the value and try formatting it as a long date as this is handled better by Access. You can still have the format of the field in rst set to short date.

Expand|Select|Wrap|Line Numbers
  1.  
  2. Dim tmpDate as Date
  3.  
  4.     If nz(RST2![AR Initial Contact Date], "") <> "" Then
  5.         tmpDate = Format(RST2![AR Initial Contact Date], "dd mmm yyyy")
  6.     Else
  7.         tmpDate = ""
  8.     End If
  9.     rst![AR Initial Contact Date] = tmpDate
  10.  
Thanks Mary! I had to change format to text and dim tmpdate as string because there were null values in many of the records but it worked like a charm! I thank you very much!
Nov 14 '07 #3
MMcCarthy
14,534 Expert Mod 8TB
Thanks Mary! I had to change format to text and dim tmpdate as string because there were null values in many of the records but it worked like a charm! I thank you very much!
You are welcome.
Nov 14 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Rob Welch | last post by:
I am changing my church band scheduling system from Excel to Database. I have assigned a schedule table in MySQL database that will be my master schedule. It contains the following fields: ...
0
by: Bernie Yaeger | last post by:
How can you import a .xml file into Excel 2002 such that it will make use of the corresponding .xsd? If you simply open the .xml, the data, column headers, etc are not properly formatted for...
9
by: Edward S | last post by:
I budget for a Project in an Excel sheet as illustrated below. The months below are usually a 2 year period i.e. 24 months, though it could be over 24 months depending upon a Project. I then...
7
by: Darren | last post by:
I have been attempting to create a reservation planning form in excel that imports Data from an Access database and inserts that information automaticly into the correct spreed sheet and the...
2
by: nutthatch | last post by:
I want to be able to import an Excel spreadsheet into Access 2K using the macro command Transferspreadsheet. However, the file I am importing (over which I have no control) contains some records...
9
by: jillandgordon | last post by:
I am trying to import an excel file into Access 97. It looks perfectly all right but, every time I try to import it, I get to the lst step and am told that it was not imported due to an error. ...
2
by: jason.teen | last post by:
Hi, I am having trouble importing a spreadsheet from Excel into an Access Database. I have noticed that even specifying the Cell Type of the Excel Data Cell, When I import it, still get...
5
by: hharriel | last post by:
Hi, I am hoping someone can help me with an issue I am having with excel and ms access. I have collected data (which are in individual excel files) from 49 different school districts. All...
2
by: ScardyBob | last post by:
Hello, I am having trouble importing data from an Excel Worksheet. When I try to import the data, everything works except certain columns that contain dates, where it replaces the date with a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.