Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 252
Default Date format - ADO query Access to Excel

I'm querying an Access db with ADO. One db field -DOB- has data of Date/Time
datatype, but when I import it, it displays as General in xl. I know I can
manually change the column format to a Date format, but I want to do it with
code.

The recordset may or may not have this field: users select the fields as
well as the order to query for by entering fields in an xl range.

Part of the code is he
strStartDate = Range("A1")
strEndDate = Range("A2")

rs1.Open "Select " & sFields & _
" From " & sTable & _
" WHERE (((DOB) Between #" & StartDate & "# And #" & EndDate &
"#))", cn

The recordset may only have 4-5 fields out of 40 in the Access Table. So I
have used the following code after the rs is dumped to xl, but this seems too
clumbsy:


'''FORMAT THE COLUMNS
On Error Resume Next
Set rDOB = ExtractFields.Find(What:=UCase("*DOB*"))
rDOB.Select
If Err < 0 Then
Err = 0
Set rDOB = ExtractFields.Find(What:=UCase("*Birth*"))
rDOB.Select
If Err < 0 Then Exit Sub
End If
Selection.EntireColumn.NumberFormat = "mm/dd/yy"

ExtractFields in the range of Headers

Isn't there a way, say in my WHERE clause to make this part of the query?

Also, the format would need to clear when a new query is run which may put
the DOB in a different column.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 593
Default Date format - ADO query Access to Excel


gocush wrote:
I'm querying an Access db with ADO. One db field -DOB- has data of

Date/Time
datatype, but when I import it, it displays as General in xl.


How are you writing the recordset data to the worksheet? When I use the
CopyFromRecordset method it seems to pick up the correct format,
including my local (UK) date format.

Jamie.

--

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Date Format Issues Access to Excel RC Excel Discussion (Misc queries) 3 June 13th 06 11:28 AM
excel - access query - date range mxp Excel Discussion (Misc queries) 1 January 31st 06 03:44 PM
Excel Query Wizard Date Format aldsv Excel Discussion (Misc queries) 1 May 31st 05 12:44 PM
Using InputBox to get desired date for a Query pulling data from Access into Excel cbeebe[_6_] Excel Programming 0 November 4th 04 09:30 PM
Using InputBox to get desired date for a Query pulling data from Access into Excel cbeebe[_5_] Excel Programming 1 November 4th 04 08:23 PM


All times are GMT +1. The time now is 01:18 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"