473,385 Members | 1,347 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,385 software developers and data experts.

Format Date Field in Table using VB

Nathan H
104 100+
I have several queries that make a new table for export. I need to find a way to format the date field in the exporting table before I output it.

Here is what I am guessing at:
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdAWBCSINGLE_Click()
  2. 'On Error GoTo RUNAPP_ERROR
  3. DoCmd.SetWarnings False
  4. DoCmd.OpenQuery "qryAWBCTEST"
  5. DoCmd.OpenQuery "qryAWBCSINGLE"
  6. Table!tblAWBC![Street Date].Format = "YYYYMMDD"
  7. DoCmd.OutputTo acOutputTable, "tblAWBC", "*.xls", , YES
  8. txtLOC.Value = "AWBC Single Title Query Completed ---" & FullExcelPath
  9. Exit Sub
  10.  
  11. RUNAPP_ERROR:
  12. End Sub
  13.  
Here is the piece I need help on (the code obviously does not work):

Table!tblAWBC![Street Date].Format = "YYYYMMDD"

The exported file needs the date field formatted this way. It goes into a third party system and does not validate without it. Opening up the spreadsheet and reformatting does not solve my problem...

Thanks for any help.
Dec 11 '07 #1
10 6912
ADezii
8,834 Expert 8TB
I have several queries that make a new table for export. I need to find a way to format the date field in the exporting table before I output it.

Here is what I am guessing at:
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdAWBCSINGLE_Click()
  2. 'On Error GoTo RUNAPP_ERROR
  3. DoCmd.SetWarnings False
  4. DoCmd.OpenQuery "qryAWBCTEST"
  5. DoCmd.OpenQuery "qryAWBCSINGLE"
  6. Table!tblAWBC![Street Date].Format = "YYYYMMDD"
  7. DoCmd.OutputTo acOutputTable, "tblAWBC", "*.xls", , YES
  8. txtLOC.Value = "AWBC Single Title Query Completed ---" & FullExcelPath
  9. Exit Sub
  10.  
  11. RUNAPP_ERROR:
  12. End Sub
  13.  
Here is the piece I need help on (the code obviously does not work):

Table!tblAWBC![Street Date].Format = "YYYYMMDD"

The exported file needs the date field formatted this way. It goes into a third party system and does not validate without it. Opening up the spreadsheet and reformatting does not solve my problem...

Thanks for any help.
Immediately prior to the Export, Format the Field exactly how you want it. Be advised that the change will persist (is permanent), so you may wish to revert back to its original Format after the Export.
Expand|Select|Wrap|Line Numbers
  1. CurrentDb.TableDefs("tblAWBC").Fields("[Street Date").Properties("Format") = "YYYYMMDD"
  2. DoCmd.OutputTo acOutputTable, "tblAWBC", acFormatXLS, , True
Dec 11 '07 #2
Nathan H
104 100+
Immediately prior to the Export, Format the Field exactly how you want it. Be advised that the change will persist (is permanent), so you may wish to revert back to its original Format after the Export.
Expand|Select|Wrap|Line Numbers
  1. CurrentDb.TableDefs("tblAWBC").Fields("[Street Date").Properties("Format") = "YYYYMMDD"
  2. DoCmd.OutputTo acOutputTable, "tblAWBC", acFormatXLS, , True

I am getting a property not found error when it runs...
Dec 11 '07 #3
Nathan H
104 100+
I am getting a property not found error when it runs...
This is a time sensitive project, so I am bouncing this back up the list.
Dec 11 '07 #4
ADezii
8,834 Expert 8TB
This is a time sensitive project, so I am bouncing this back up the list.
I'm not sure what the problem is, the code has been tested and is functional. Try checking you syntax.
Dec 11 '07 #5
Nathan H
104 100+
I'm not sure what the problem is, the code has been tested and is functional. Try checking you syntax.
First Error:
When I run this I get: "Item Not Found in this Collection"

Expand|Select|Wrap|Line Numbers
  1. CurrentDb.TableDefs("tblAWBC").Fields("[Street Date").Properties("Format") = "YYYYMMDD"
  2.  
Second Error:
When I tried this, because it looked like a typo I get this error: "Property Not Found"

Expand|Select|Wrap|Line Numbers
  1. CurrentDb.TableDefs("tblAWBC").Fields("Street Date").Properties("Format") = "YYYYMMDD"
  2.  
Dec 11 '07 #6
Nathan H
104 100+
First Error:
When I run this I get: "Item Not Found in this Collection"

Expand|Select|Wrap|Line Numbers
  1. CurrentDb.TableDefs("tblAWBC").Fields("[Street Date").Properties("Format") = "YYYYMMDD"
  2.  
Second Error:
When I tried this, because it looked like a typo I get this error: "Property Not Found"

Expand|Select|Wrap|Line Numbers
  1. CurrentDb.TableDefs("tblAWBC").Fields("Street Date").Properties("Format") = "YYYYMMDD"
  2.  

ADezii,

The code runs when I go into the table, define a format (like long date), close the table, and then run the code.

It looks like I have to go and create the property first. First time trying, so any pointers would be most helpful.

Nathan
Dec 11 '07 #7
missinglinq
3,532 Expert 2GB
On this line
Expand|Select|Wrap|Line Numbers
  1. CurrentDb.TableDefs("tblAWBC").Fields("[Street Date").Properties("Format") = "YYYYMMDD"
  2.  
you've got an unmatched square bracket before Street Date! Unmatched brackets re never happy!

Linq ;0)>
Dec 11 '07 #8
Nathan H
104 100+
On this line
Expand|Select|Wrap|Line Numbers
  1. CurrentDb.TableDefs("tblAWBC").Fields("[Street Date").Properties("Format") = "YYYYMMDD"
  2.  
you've got an unmatched square bracket before Street Date! Unmatched brackets re never happy!

Linq ;0)>
Linq,

I think we have that fixed. Problem is now I have to create the "format" property in the code, but have no experience with that. Any advice?

Nathan
Dec 11 '07 #9
ADezii
8,834 Expert 8TB
ADezii,

The code runs when I go into the table, define a format (like long date), close the table, and then run the code.

It looks like I have to go and create the property first. First time trying, so any pointers would be most helpful.

Nathan
As Linq pointed out, the only problem should be the missing right bracket in the [Street Date] Field. It should run now:
Expand|Select|Wrap|Line Numbers
  1. CurrentDb.TableDefs("tblAWBC").Fields("[Street Date]").Properties("Format") = "YYYYMMDD"
Dec 12 '07 #10
Nathan H
104 100+
As Linq pointed out, the only problem should be the missing right bracket in the [Street Date] Field. It should run now:
Expand|Select|Wrap|Line Numbers
  1. CurrentDb.TableDefs("tblAWBC").Fields("[Street Date]").Properties("Format") = "YYYYMMDD"

Hey All,

Let me try to explain. The code does run fine, but only after I have opened up the created table, insert something in the "Format" properties box, close the table, and then run the code.

It does not work if I do not do these steps. The field does not have the "Format" property attached to it prior to these steps, so if I run the code it does not find the property "format".

I think that before this line of code, I need to either create an instance of the property "format" attached to the field, or something....it is frustrating.

thanks for all your brain power so far.

Nathan
Dec 12 '07 #11

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

Similar topics

4
by: peashoe | last post by:
I have an asp page that uses a calendar.js (pop-up) file to add an exact date format in the text field (txtDDate). My problem is I need some javascript that sets an alert that does not allow them...
3
by: usenet | last post by:
I have inherited a table where date information was saved from PHP as a VARCHAR. (Sigh.) This means that the so-called date fields look like this : August 1, 2005, 9:09 am EDT October 13, 2004,...
0
by: lsy | last post by:
i wonder how can i order my statement interm of "ORDER BY FORMAT(Date, 'mmmm')" with using this it will order by alphabethical but i want it order by month... i had try "ORDER BY FORMAT(Date, 'mm')"...
3
by: Fran Zablocki | last post by:
I have a process that exports an Access table to a comma-delimited text file. One of the fields that is exported shows the date it was exported, using the Date() function. In the Access table, the...
4
by: Stewart Allen | last post by:
I'm trying to filter a table that has 2 date fields, the first date will always have a value but the second will only occasionally has a value. Each date field also has a corresponding text field...
4
by: S. van Beek | last post by:
Dear reader, By a Date field with Now() as default value the content of the field is date plus time. As I need a filter in a query on date only (excluding time) I invented the following...
2
by: Paul | last post by:
I am trying to insert a date into a mysql table but everytime I attempt it the date field is always empty. The field is of Date type and the date in code is in European format dd/mm/yyyy. ...
1
by: G Gerard | last post by:
Hello I am having some problem comparing dates with the SQL statement below MySQL = "SELECT Format(Date, 'yyyy/mmmm/dd') as FROM TblDates WHERE _ Format(Date, 'yyyy/mmmm/dd') =...
2
by: sparks | last post by:
I am trying to find valid records in a table but I must compare a date field to a date stored in the table I can see where this is wrong (ok I guess its not text) "= """ & Me.date & """" so...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.