Print # format

rbs

Board Regular
Joined
Oct 6, 2002
Messages
58
Hi Everyone,

I have a module creating a dat file in which it writes records from my query without using delimiters.

I have a problem in that it is exporting date fields in the wrong format. Within the query a date is set in the format yyyymmdd. But when the data is transfered it comes through as dd/mm/yyyy.

Can anyone tell me how to fix this?

Thanks in advance.


Natalie.
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
You have to explicitly set the date format in the export, or Access will default to your regional setting.

Assuming you have [MyDate] as a field, you could try ...
declaring MyFormattedDate as a String.
MyFormattedDate = Format$([MyDate],"yyyymmdd")
... and exporting the string instead of the date.

HTH
Denis
 
Upvote 0
Thanks for your help...

I have set up the module as follows:

........
Dim SellInTxnDate As String
........

Set db1 = CurrentDb
Set recset1 = db1.OpenRecordset("PURCHASES DAILY ALL QUERY")

With recset1

Do Until .EOF

.......
SellInTxnDate = !Format$([Txn Date], "yyyymmdd")
.......

Open Name For Append As #1

Print #1, ..... & SellInTxnDate & .....
Close #1 'close the text file

.MoveNext
Loop
.Close

End With


It comes back saying

Compile Error
External Name not defined refererring to the line:

SellInTxnDate = !Format$([Txn Date], "yyyymmdd")


Can you help?
 
Upvote 0
Try changing this...
SellInTxnDate = !Format$([Txn Date], "yyyymmdd")
to this...
SellInTxnDate = Format$(![Txn Date], "yyyymmdd")
or this...
SellInTxnDate = Format$([Txn Date], "yyyymmdd")
Does that help?

Putting the exclamation in front of Format tells Access to look for a field, where you are referring to a function here :)
Denis
 
Upvote 0

Forum statistics

Threads
1,221,572
Messages
6,160,575
Members
451,656
Latest member
SBulinski1975

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top