473,385 Members | 1,863 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.

Using VBA to Export a CSV File To Include Brackets

I need to export a file through VBA, but as part of the file name is to include a Date/Time stamp in brackets.

Here's what I have:
Expand|Select|Wrap|Line Numbers
  1. strExportFileName = "C:\My Documents\" & strPositivePayFileName & "[" & Format(Date, "mmdd") & Format(Time, "hhnn") & "].csv"
  2.  
and the Export Code:
Expand|Select|Wrap|Line Numbers
  1. DoCmd.TransferText acExportDelim, "Positive Pay Export Specification", "qryPositivePayExport", strPositivePayExportFileName, True
  2.  
When I run it, I get the following error:
Run-time Error:'3125'"

'0010520[082620101131].csv' is not a valid name. Make sure that it does not include invalid characters or punctuation and that it is not too long.


Any help would be much appreciated.

Thanks in advance.

Jeff
Aug 26 '10 #1
7 3096
NeoPa
32,556 Expert Mod 16PB
Are you positive this is exactly how it was Jeff?

I did some testing and found that filename to work perfectly well.

The syntax for the command is also ok with the parameters in the correct position from what I can see.
Aug 26 '10 #2
Neo -

It is....I have msgboxes that shows that it is.

Funny thing is...when I change to parentheses, it works, but not brackets, which is what I need.
Aug 26 '10 #3
NeoPa
32,556 Expert Mod 16PB
It was a long shot Jeff, though I did testing my end and I didn't get the same issues.

This appears to be an OS issue rather than anything to do with Access or VBA specifically, but let's confirm that here for sure first. Could you try running the test I did, then I know the full situation.

Open Windows Explorer (Windows key-E)
Navigate to the folder you were attempting to create the file in with your code and, using Right-Click, select New / Text Document.
Next, type in the name you were attempting to use earlier (0010520[082620101131].csv) and hit enter.
On my system, this works fine and creates an empty file.

What response do you get?
Aug 27 '10 #4
The same...it created the file.

Here's the complete code...
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdGenerateFile_Click()
  2.     Dim strExportFileName As String
  3.     Dim strPositivePayFileName As String
  4.     Dim strPositivePayExportFileName As String
  5.     Dim blnIncludeYear As Boolean
  6.     Dim blnUseBankNaming As Boolean
  7.     Dim strBankAccountNumber As String
  8.  
  9.     blnUseBankNaming = DLookup("UseBankNamingonPositivePay", "tblAccountingBankOptions")
  10.     strBankAccountNumber = DLookup("BankAccount", "tblAccountingBankOptions")
  11.  
  12.     If blnUseBankNaming = True Then
  13.         strPositivePayFileName = DLookup("PositivePayFileName", "tblSystemOptions")
  14.         blnIncludeYear = DLookup("IncludeYearInPositivePay", "tblAccountingBankOptions")
  15.  
  16.  
  17.         If blnIncludeYear = True Then
  18.             strExportFileName = "C:\My Documents\0010520[" & Format(Date, "mmddyyyy") & Format(Time, "hhnn") & "].csv"
  19.         Else
  20.             strExportFileName = "C:\My Documents\" & strPositivePayFileName & "[" & Format(Date, "mmdd") & Format(Time, "hhnn") & "]"
  21.         End If
  22.         DoCmd.SetWarnings False
  23.         DoCmd.RunSQL ("UPDATE tblSystemOptionsLocalUser SET PositivePayFileName='" & strExportFileName & "'")
  24.         DoCmd.SetWarnings True
  25.         strPositivePayExportFileName = DLookup("PositivePayFileName", "tblSystemOptionsLocalUser")
  26.     'MsgBox strExportFileName
  27.     DoCmd.TransferText acExportDelim, "Positive Pay Export Specification", "qryPositivePayExport", strExportFileName, True
  28.  
  29.     Else
  30.     DoCmd.SetWarnings False
  31.     DoCmd.RunSQL ("UPDATE tblSystemOptionsLocalUser SET PositivePayFileName='PositivePay.csv'")
  32.     DoCmd.SetWarnings True
  33.     DoCmd.TransferText acExportDelim, "Positive Pay Export Specification", "qryPositivePayExport", "C:\My Documents\PositivePay.csv", True
  34.     End If
  35.  
  36. End Sub
  37.  
Aug 27 '10 #5
NeoPa
32,556 Expert Mod 16PB
JTGarrison:
Here's the complete code...
Nothing there of any interest I'm afraid.

I did try to duplicate your situation in the code though. I don't have your export spec or data but I used something I had which was as similar as possible. I got an error, but 1026 :
Expand|Select|Wrap|Line Numbers
  1. Run-time error '2006':
  2.  
  3. The object name '001020[082620101131]#csv' you entered doesn't follow Bytes object naming rules.
I should point out two things for clarification :
  1. I used exactly the same name as you, if not the same folder. My actual call was :
    Expand|Select|Wrap|Line Numbers
    1. Call DoCmd.TransferText(acExportDelim, _
    2.                         "CSV Spec", _
    3.                         "tblErr", _
    4.                         "C:\Temp\0010520[082620101131].csv")
  2. Bytes is the name of the database I tested it on.
This clearly is an Access issue after all and not an OS one.

I got around it by using :
Expand|Select|Wrap|Line Numbers
  1. Call DoCmd.TransferText(acExportDelim, _
  2.                         "CSV Spec", _
  3.                         "tblErr", _
  4.                         "C:\Temp\0010520(082620101131).csv")
  5. Name "C:\Temp\0010520(082620101131).csv" As "0010520[082620101131].csv"
Aug 27 '10 #6
Thanks for the info...will try it out when I get a few minutes.
Aug 27 '10 #7
NeoPa
32,556 Expert Mod 16PB
Let us know how you get on.
Sep 6 '10 #8

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

Similar topics

3
by: Prakash | last post by:
Hi, We face problems uploading excel (with macros) documents using HTML File Upload. The file contents are corrupted while viewing the same. However, we are able to upload excel (w/o. macros)...
3
by: Roel Schoonveld | last post by:
In Access 97 I made an application that makes text files that are exported. The names of the files contain two variables: 1. the value of the field BRIN in a table VasteGegevens of my database....
1
by: VB Programmer | last post by:
I have a comma delimited export file with 10 columns. I want to display the first 5 and the last 2 columns in a datagrid or table. Is there any way to do this automatically? If not, does anyone...
12
by: Steve Pope | last post by:
Compiling the following works on my system: file main.cpp: #include <iostream> namespace space { int foo; }
0
by: Spam Catcher | last post by:
Hi all, Are there any good export file libraries besides filehelpers? http://filehelpers.sourceforge.net/ I'm looking for something where I can pass in a DataTable, Collection, etc, and the...
3
by: Frank | last post by:
Hi, I simply wish to code a JS function ONCE, in a .js file, include the .js file in the Master page, and then in several but not all pages, I wish to execute the function on pageload. I...
4
by: HoganGroup | last post by:
I need to create an export file for the following brutal query to upload into a state database (go figure it's a government report!) All was good in my world until I tried to export. Manually or...
2
by: DJ Dharme | last post by:
Hi all, I am writing a multi-threaded application in c++ running on solaris. I have a file which is updated by a single thread by appending data into the file and at same time the other threads...
3
omerbutt
by: omerbutt | last post by:
hi there i am trying to run the lightbox and a slider on a single page the light box is working allrigh but when i try to include the slider in the same page it generates error because i have to...
8
by: Amera | last post by:
hello, i have tried alot of things about this but in the end i did it using flat file. but the response is so slow -_-" i'm passing a character between C and C# using a text file. this...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...

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.