473,668 Members | 2,365 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Importing Dates from Excel

57 New Member
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 1786
MMcCarthy
14,534 Recognized Expert Moderator MVP
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
DThreadgill
57 New Member
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 Recognized Expert Moderator MVP
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
1169
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: SCHEDULE TABLE ----------------------------------------- eventid (refers to a field in my events table that contain dates and types of events on that date) playerid (refers to a field in my players table that contains a list of...
0
1961
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 strings that appear to be numbers, dates, etc. I've posted to an Excel ng, but I was hoping someone here might know. Tx for any help. Bernie Yaeger
9
4030
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 need to input this in an Access database, where I do a comparison with the Actual cost. The table “TblBudget” in Access is made of 4 fields, namely: (1) CostElement (2) CostCenter (3) Month (4) Amount$. At the moment this method is very cumbersome....
7
3054
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 correct cells within that worksheet. The Excel Book is made up of 12 worksheets named Jan-Dec. Each worksheet has columns labeled as each day of that month. Column 'A' is reserved for 19 rows named "room1 - room19". The data I am importing from the...
2
3605
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 that are "dirty" i.e. the field contents do not comply with the expected format (date/time) and they end up in a seperate table of import errors. (The records in "error" are actually empty fields.) This is a regular event and I do not want to...
9
3910
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. There is no further explanation. What are the kinds of things that make this happen? Thanks from an obvious rookie. Gordon
2
2352
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 Import Errors. Like Type Mismatch. The funny thing is that its all done automatically via the Wizard, so I dont even specify what the field type should be in my database, but it
5
3168
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 districts have used the same excel template and populated the same 32 data fields (columns). I created one large excel file from all 49 files which gives me a master table of 60,000 or so records. I have tried to import this master table into access...
2
1915
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 null in the access table. To import the data I do the following. 1. Create a table based on the excel spreadsheet setup with the following query sSQL = "INSERT INTO " & TblName & " SELECT * " _
0
8462
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8893
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8799
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8586
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7401
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5681
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4380
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2026
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1786
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.