469,943 Members | 2,576 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,943 developers. It's quick & easy.

Automating a command button to do a Get External Data command

I'm trying to use a command button to the same thing as going to the
file menu and doing a Get External Data command to make the import
process easier for some end users. I'm using Access 2k, I have the
following code but I can't seem to get it to work properly.

Private Sub Command18_Click()
Dim strFileName As String
Dim strPath As String

strPath = "C:\ data" 'the location of the files
strFileName = "report.csv"

DoCmd.TransferText acImportDelim, "Data", strPath &
strFileName, "PC_Date", False
End Sub

Is there someone that can tell me what I'm missing or what I have
wrong.
Thanks

Dec 9 '05 #1
3 2367
Br
Bill wrote:
I'm trying to use a command button to the same thing as going to the
file menu and doing a Get External Data command to make the import
process easier for some end users. I'm using Access 2k, I have the
following code but I can't seem to get it to work properly.

Private Sub Command18_Click()
Dim strFileName As String
Dim strPath As String

strPath = "C:\ data" 'the location of the files
strFileName = "report.csv"

DoCmd.TransferText acImportDelim, "Data", strPath &
strFileName, "PC_Date", False
End Sub

Is there someone that can tell me what I'm missing or what I have
wrong.
Thanks
First, did you check the Access help? I've included a snippet from it
below.

It is hard to diagnose the problem when you don't tell us what happens
when you run the code? Nor do we get a clear indication of what "data"
and "PC_Date" are?

---------- From the Access Help

Syntax:

DoCmd.TransferText [transfertype][, specificationname], tablename,
filename[, hasfieldnames][, HTMLtablename][, codepage]

Remarks
You can leave an optional argument blank in the middle of the syntax,
but you must include the argument's comma. If you leave a trailing
argument blank, don't use a comma following the last argument you
specify.

----------
DoCmd.TransferText acImportDelim, "Data", strPath &
strFileName, "PC_Date", False


According to the syntax desscription your code reads:

Transfertype = acImportDelim (ok)
SpecificationName = "Data"
Tablename = strPath & strFileName
Filename = "PC_Date"
HasFieldNames = False

Don't forget to include commas for all the options even if you are
leaving them blank (except ones that are at the end of the line).

eg. No value given for specification, HTMLtablename, or Codepage

Docmd.TransferText acImportDelim, ,"tblMyTable", "c:\myfile.txt", False
--
regards,

Bradley

A Christian Response
http://www.pastornet.net.au/response
Dec 9 '05 #2
I have the command working now but because some of the headers have a
"." in the name its seeing the period as a delimiting character.
Because this is happening it's not finding the corresponding fields in
the table. Is there a way of telling it to only look for commas ","
to separate the data??

Dec 9 '05 #3
I was wrong. What is really happening is that the "." showing up as a
"#" and that is the reason that I can't get it to compleatly inport the
data. Any Ideas as to why that might be happening and how to fix the
problem??

Dec 9 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by James Johnson | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.