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: - strExportFileName = "C:\My Documents\" & strPositivePayFileName & "[" & Format(Date, "mmdd") & Format(Time, "hhnn") & "].csv"
-
and the Export Code: - DoCmd.TransferText acExportDelim, "Positive Pay Export Specification", "qryPositivePayExport", strPositivePayExportFileName, True
-
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
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.
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.
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?
The same...it created the file.
Here's the complete code... - Private Sub cmdGenerateFile_Click()
-
Dim strExportFileName As String
-
Dim strPositivePayFileName As String
-
Dim strPositivePayExportFileName As String
-
Dim blnIncludeYear As Boolean
-
Dim blnUseBankNaming As Boolean
-
Dim strBankAccountNumber As String
-
-
blnUseBankNaming = DLookup("UseBankNamingonPositivePay", "tblAccountingBankOptions")
-
strBankAccountNumber = DLookup("BankAccount", "tblAccountingBankOptions")
-
-
If blnUseBankNaming = True Then
-
strPositivePayFileName = DLookup("PositivePayFileName", "tblSystemOptions")
-
blnIncludeYear = DLookup("IncludeYearInPositivePay", "tblAccountingBankOptions")
-
-
-
If blnIncludeYear = True Then
-
strExportFileName = "C:\My Documents\0010520[" & Format(Date, "mmddyyyy") & Format(Time, "hhnn") & "].csv"
-
Else
-
strExportFileName = "C:\My Documents\" & strPositivePayFileName & "[" & Format(Date, "mmdd") & Format(Time, "hhnn") & "]"
-
End If
-
DoCmd.SetWarnings False
-
DoCmd.RunSQL ("UPDATE tblSystemOptionsLocalUser SET PositivePayFileName='" & strExportFileName & "'")
-
DoCmd.SetWarnings True
-
strPositivePayExportFileName = DLookup("PositivePayFileName", "tblSystemOptionsLocalUser")
-
'MsgBox strExportFileName
-
DoCmd.TransferText acExportDelim, "Positive Pay Export Specification", "qryPositivePayExport", strExportFileName, True
-
-
Else
-
DoCmd.SetWarnings False
-
DoCmd.RunSQL ("UPDATE tblSystemOptionsLocalUser SET PositivePayFileName='PositivePay.csv'")
-
DoCmd.SetWarnings True
-
DoCmd.TransferText acExportDelim, "Positive Pay Export Specification", "qryPositivePayExport", "C:\My Documents\PositivePay.csv", True
-
End If
-
-
End Sub
-
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 : - Run-time error '2006':
-
-
The object name '001020[082620101131]#csv' you entered doesn't follow Bytes object naming rules.
I should point out two things for clarification : - I used exactly the same name as you, if not the same folder. My actual call was :
- Call DoCmd.TransferText(acExportDelim, _
-
"CSV Spec", _
-
"tblErr", _
-
"C:\Temp\0010520[082620101131].csv")
- 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 : - Call DoCmd.TransferText(acExportDelim, _
-
"CSV Spec", _
-
"tblErr", _
-
"C:\Temp\0010520(082620101131).csv")
-
Name "C:\Temp\0010520(082620101131).csv" As "0010520[082620101131].csv"
Thanks for the info...will try it out when I get a few minutes.
NeoPa 32,556
Expert Mod 16PB
Let us know how you get on.
Sign in to post your reply or Sign up for a free account.
Similar topics
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)...
|
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....
|
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...
|
by: Steve Pope |
last post by:
Compiling the following works on my system:
file main.cpp:
#include <iostream>
namespace space {
int foo;
}
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
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...
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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: 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...
|
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,...
| |