|
-
July 6th, 2007, 10:56 AM
#1
Imported access file(date values) into excel sprdsheet converts to numbers(integer)
Good morning everyone - I am using VB6.
I need your assistance. I used the "CopyFromRecordset" function to populate my spreadsheet. Some of the fields in the access file has date values and some has number values (integers), but after importing into the spreadsheet, the numbers convert to date values(1/1/1900) and the date fields displays number values in the columns that was supposed to display dates.
I have used the code below to try and fix the problem and the numbers displays correctly, but the date values are still displaying numbers (integers).
My code:
Code:
Columns("A:A").Select
xlApp.Selection.NumberFormat = "###"
xlApp.Selection.Columns.AutoFit
<==This works fine.
Code:
Columns("L:L").Select
xlApp.Selection.NumberFormat = "mm/dd/yyyy"
xlApp.Selection.Columns.AutoFit
<==This does not work.
Thanks.
GiftX
-
July 6th, 2007, 11:32 AM
#2
Re: Imported access file(date values) into excel sprdsheet converts to numbers(integ
Record a macro in Excel, and see what needs to be done.
-
July 6th, 2007, 01:34 PM
#3
Re: Imported access file(date values) into excel sprdsheet converts to numbers(integ
Make sure your columns are not already formatted with an incorrect formatting type for what you are expecting.
Since you are using the .CopyFromRecordset method there isnt a whole lot you can do because its done internally and a macro wont show its process. 
You can do like you have done and code in the proper formatting of the columns.
I would go with this code instead though in order to avoid using the Selection method in an effort to improve resource useage and speed. 
Code:
xlApp.YourWorkbookObject.Sheets("Sheet1").Columns("A:A").NumberFormat = "###"
xlApp.YourWorkbookObject.Sheets("Sheet1").Columns("A:A").AutoFit
xlApp.YourWorkbookObject.Sheets("Sheet1").Columns("L:L").NumberFormat = "mm/dd/yyyy"
xlApp.YourWorkbookObject.Sheets("Sheet1").Columns("L:L").AutoFit
-
July 6th, 2007, 05:43 PM
#4
Re: Imported access file(date values) into excel sprdsheet converts to numbers(integer)
Thanks for your imput. I'll try it out on Monday.
Meanwhile, you all enjoy your weekend.
GiftX.
-
July 9th, 2007, 11:21 AM
#5
Re: Imported access file(date values) into excel sprdsheet converts to numbers(integer)
I tried using "DateFormat" in the code below, but I got error msg:
"Object does not support this property".
First, I tried this code:
xlApp.xlWbk.Sheets("Sheet1").Columns("H:H").DateFormat = "mm/dd/yyyy"
And I also tried this code:
xlWksht.Range("G:G,H:H,K:K,L:L").Select
Selection.DateFormat = "mm/dd/yyyy"
In all the codes above, I used both "DateFormat" and "NumberFormat", but the date fields in access file still returns numbers in my spreadsheet.
GiftX
-
July 9th, 2007, 12:38 PM
#6
Re: Imported access file(date values) into excel sprdsheet converts to numbers(integ
Do your cells look like this?
123107 7/8/2007 112206 8/8/2007
I had no problem formatting that as Date
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|