473,699 Members | 2,801 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Access VBA to format Excel - Date Format

8 New Member
Dear All,

I am trying to format the data to DMY in the excel file which is exported to excel using the transfer spreadsheet command. I am trying to format using text to columns as udner.

Expand|Select|Wrap|Line Numbers
  1.   .Range("AA2", xlapp.Range("AA65536").End(xlUp)).Select
  2.             .Selection.TextToColumns Destination:=xlapp.Range("AA2"), DataType:=xlDelimited, _
  3.             TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
  4.             Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
  5.             :=Array(1, 4), TrailingMinusNumbers:=True
  6.  


The concern here is that the date format does to change to dmy for example 01/07/2011 post the code above changes to 07/01/2011.

request help ... Thank You in advance.
May 9 '11 #1
7 7696
NeoPa
32,569 Recognized Expert Moderator MVP
You need to decide first of all whether you are dealing with dates (in which case only the formatting of the cell will determine how they are displayed) or with strings that look like dates (in which case a formula would be required ="01/07/2011" or a single-quote (') would need to be used as the first character of the value '07/01/2011).
May 11 '11 #2
Vishnu R
8 New Member
The field contains dates stored as strings/text. Also, i tried the text to columns after exporting the raw file where all dates are stored as text within excel. The conversion was as desired in dmy format. Hence am a little confused as to why the text to columns in excel does not work with the same results through access.

Hence as an alternative, can we include an excel module in the file eported through access whcih can be run on opeing the excel file.
May 11 '11 #3
NeoPa
32,569 Recognized Expert Moderator MVP
Vishnu, when dealing in technical matters your answers need to be clearer. "The field" can mean so many dferent things in this context that it tells me nothing. The rest of the wording tells me nothing either as it doesn't even indicate that you understand the difference between the two possibilities (I'm happy if you do of course, but I need to know it before we can proceed).

The second question is premature at this stage.

Please answer these questions clearly :
  1. Is the table field where the date data is stored defined as Text?
  2. When the data is exported into Excel is the data there a string or a date value? You can determine this by selecting the cell and changing the format to another numeric/date format. String values will appear the same as before, whereas numeric/date values will change to match the new formatting.
May 11 '11 #4
Vishnu R
8 New Member
NeoPa, I am sorry, I was not clear...

1) This is a text field. The field contains the spouse date of birth for employees. It also holds blank fields.

2)The exported data is a string.

Thank You
May 11 '11 #5
NeoPa
32,569 Recognized Expert Moderator MVP
That's a good clear answer.

Now what confuses me is exactly what you are doing to reformat the data. Text to Columns should work with textual data (as you have) but I cannot see how the code you've posted would be expected to change the format to DMY. Is that what you want to do? If not then please explain exactly what it is you are trying to do with the data.
May 12 '11 #6
Vishnu R
8 New Member
I was able to fix the concern by adding the following code before executing text to columns.
Expand|Select|Wrap|Line Numbers
  1. .Selection.NumberFormat = "dd/mm/yyyy;@"
  2.  
It is working for now..
Thank you NeoPa for your guidance...I will need more of it in the future.
May 12 '11 #7
NeoPa
32,569 Recognized Expert Moderator MVP
Interesting. I'm not sure I follow exactly why that would result in a recognisable string value, but if it does then that takes us back to my suggestion in post #2. Perhaps you should have explored that a little more carefully before your post #3.

Not important though. You have a solution now and that's the most important thing. It's often hard to notice the answer when you're confused yourself, even when you see it.
May 12 '11 #8

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

Similar topics

1
60915
by: jt | last post by:
I posted this yesterday, but I am not seeing this out yet: I am having problems with updating a date field in a certain format. The data is stored in an Oracle database. The date is automatically displayed in format, "mm/dd/yyyy" on the ASP page, but it is accepted only in another format, "dd/mon/yy". I want to make it consistent. How can I force it to accept the date in format "mm/dd/yyyy"? The second option would be to force it to...
0
1242
by: Neil10365 | last post by:
I am sure I must be doing something wrong but here it is: I import an excel spreadsheet that has dates in the format mm/dd/yyy. The receiving table in access has a date field set to mm/dd/yy, which is what I want. The dates are now displayed with a two digit year. The problem comes when I export the results to excel. When I open the spreadsheet the dates are back to mm/dd/yyyy again! Can I force excel to obey me? and keep the dates in...
9
6368
by: insomniux | last post by:
Hi, I am having a problem with formatting the default value of a date field. It has been discussed earlier in many topics, but still I cannot solve the problem. What's happening: I have various forms which are based on an ODBC-linked tables. In one of the forms, I have a control which shows the date of a date field in my database (storage type=date). The default value for the control is set to '=Date()', the format property is set to...
4
3338
by: krupalreddy | last post by:
i have a problem with date i have two dates. one is in Date type and the other one is in String type. i need to compare these two dates. for this i try to convert date which is in String type to Date type.is it possible? how?could you suggest the logic and methods?
10
5811
by: ARC | last post by:
Hello all, General question for back-end database that has numerous date fields where the database will be used in regions that put the month first, and regions that do not. Should I save a date format in the table design, such as: mm/dd/yyyy? What I've done for years is to store the date format in date fields, then on the forms, based on their region, I would set the date formats on form_load
4
2002
by: fercic | last post by:
Hi folks ! I'm not able to get a date before 01/01/1930 formatted as short date (dd/mm/yy). It is always formatted as dd/mm/yyyy. Any idea? fercic
3
4586
by: Bface | last post by:
Hi all, Hope everyone had a good holiday. I am having a difficult time changing the date format of a field from Excel. I have never had this problem before. I link the excel spreadsheet to my DB, from the spreadsheet I have an append query that appends only certain fields from the spreadsheet to a table. One of the fields is called . The date in this field are displayed as ‘yyyymmdd’ ex:20070525 To change date format I usually create an...
18
13035
by: Dirk Hagemann | last post by:
Hello, From a zone-file of a Microsoft Active Directory integrated DNS server I get the date/time of the dynamic update entries in a format, which is as far as I know the hours since january 1st 1901. For Example: the number 3566839 is 27.11.07 7:00. To calculate this in Excel I use this: ="01.01.1901"+(A1/24-(REST(A1;24)/24))+ZEIT(REST(A1;24);0;0) (put 3566839 in field A1 and switch the format of the result-field to the corresponding...
1
3053
by: accessvbanewbie | last post by:
I would like to export a recordset from access to excel but after each record is exported I want to insert a new row. The first recordset does this ok. However, the second recordset onwards does not not export line excelsheet.Cells(9, 2) = rsschedulesrecords.Fields(2).Value. Below is my code. Please help? Private Sub CreateDailyRoster(rsschedulesrecords As DAO.Recordset) Dim excelapp As New Excel.Application Dim excelfile As...
0
8686
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
9173
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
8882
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7748
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...
1
6533
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5872
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
4627
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2345
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2009
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.