User selects file, then import into table

G

Guest

I want to allow a user browse a file and after the file is selected, I want
that file to be imported into a table. This is all in access 2000.

Right now, after the user selects the file to import, I get an run-time
error 2522: "the action or method requires a file name argument"

I know that the standard transfertext command asks for a file name in the
argument, but in this case, I want the file that was selected by the user to
be imported. That file name may change each import.

Please help - as you can tell, I am very green on VB. I have searched all
the help files I can find - no luck so far.

Here is my code:

Private Sub cmdFileDialog_Click()

Dim strFilter As String
Dim strInputFileName As String

strFilter = ahtAddFilterItem(strFilter, "Tab Files (*.tab)", "*.tab")
strInputFileName = ahtCommonFileOpenSave( _
Filter:=strFilter, OpenFile:=True, _
DialogTitle:="Please select an input file...", _
Flags:=ahtOFN_HIDEREADONLY)
DoCmd.TransferText acExportDelim, "Alibris Import specification",
"AlibrisImportTable", ""

End Sub
 
D

Douglas J. Steele

The syntax for the TransferText method is

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

You need to replace the final "" in your string with strInputFileName
 
G

Guest

The file name changes - it will never be constant, so I cannot put the
filename into the code... That is the point of having the user pull up the
dialog box... How do I get the file selected in the dialog box to be the
file the command imports.

Douglas J. Steele said:
The syntax for the TransferText method is

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

You need to replace the final "" in your string with strInputFileName

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



BLTibbs said:
I want to allow a user browse a file and after the file is selected, I want
that file to be imported into a table. This is all in access 2000.

Right now, after the user selects the file to import, I get an run-time
error 2522: "the action or method requires a file name argument"

I know that the standard transfertext command asks for a file name in the
argument, but in this case, I want the file that was selected by the user
to
be imported. That file name may change each import.

Please help - as you can tell, I am very green on VB. I have searched all
the help files I can find - no luck so far.

Here is my code:

Private Sub cmdFileDialog_Click()

Dim strFilter As String
Dim strInputFileName As String

strFilter = ahtAddFilterItem(strFilter, "Tab Files (*.tab)", "*.tab")
strInputFileName = ahtCommonFileOpenSave( _
Filter:=strFilter, OpenFile:=True, _
DialogTitle:="Please select an input file...", _
Flags:=ahtOFN_HIDEREADONLY)
DoCmd.TransferText acExportDelim, "Alibris Import specification",
"AlibrisImportTable", ""

End Sub
 
A

Albert D.Kallal

BLTibbs said:
The file name changes - it will never be constant, so I cannot put the
filename into the code... That is the point of having the user pull up
the
dialog box... How do I get the file selected in the dialog box to be the
file the command imports.

What ever variable you stuff in the filename can be used. Can't read you
mind, but lets assume you use

dim strFileName as string


' code here to put file name in above var...

You can use the sample api code, or, for quick testing, just use:

strFileName = inputbox("what file name")

docmd.TransferText acImportDelim,,"tblResults",strFileName,true

Now, I don't know if that text file is delimited, fixed width etc. So, once
again, check the help on transfer text, or use inteli-sense as you type

Furhter, you *LIKEY* need to create a import spec. This is done when you
import the file manually for the first time using the wziard (click on the
advanced tap...and save a spec name. After you make the spec name, then use

docmd.TransferText
acImportDelim,"nameofyourspecgoeshere","tblResults",strFileName,true
 
D

Douglas J. Steele

Based on the code you showed, strInputFileName is what you picked from the
dialog box.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



BLTibbs said:
The file name changes - it will never be constant, so I cannot put the
filename into the code... That is the point of having the user pull up
the
dialog box... How do I get the file selected in the dialog box to be the
file the command imports.

Douglas J. Steele said:
The syntax for the TransferText method is

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

You need to replace the final "" in your string with strInputFileName

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



BLTibbs said:
I want to allow a user browse a file and after the file is selected, I
want
that file to be imported into a table. This is all in access 2000.

Right now, after the user selects the file to import, I get an run-time
error 2522: "the action or method requires a file name argument"

I know that the standard transfertext command asks for a file name in
the
argument, but in this case, I want the file that was selected by the
user
to
be imported. That file name may change each import.

Please help - as you can tell, I am very green on VB. I have searched
all
the help files I can find - no luck so far.

Here is my code:

Private Sub cmdFileDialog_Click()

Dim strFilter As String
Dim strInputFileName As String

strFilter = ahtAddFilterItem(strFilter, "Tab Files (*.tab)", "*.tab")
strInputFileName = ahtCommonFileOpenSave( _
Filter:=strFilter, OpenFile:=True, _
DialogTitle:="Please select an input file...", _
Flags:=ahtOFN_HIDEREADONLY)
DoCmd.TransferText acExportDelim, "Alibris Import specification",
"AlibrisImportTable", ""

End Sub
 
G

Guest

Doug, - Thanks, after about 20 minutes of feeling dumb, I did finally figure
that out! But thanks for writing.

Douglas J. Steele said:
Based on the code you showed, strInputFileName is what you picked from the
dialog box.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



BLTibbs said:
The file name changes - it will never be constant, so I cannot put the
filename into the code... That is the point of having the user pull up
the
dialog box... How do I get the file selected in the dialog box to be the
file the command imports.

Douglas J. Steele said:
The syntax for the TransferText method is

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

You need to replace the final "" in your string with strInputFileName

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



I want to allow a user browse a file and after the file is selected, I
want
that file to be imported into a table. This is all in access 2000.

Right now, after the user selects the file to import, I get an run-time
error 2522: "the action or method requires a file name argument"

I know that the standard transfertext command asks for a file name in
the
argument, but in this case, I want the file that was selected by the
user
to
be imported. That file name may change each import.

Please help - as you can tell, I am very green on VB. I have searched
all
the help files I can find - no luck so far.

Here is my code:

Private Sub cmdFileDialog_Click()

Dim strFilter As String
Dim strInputFileName As String

strFilter = ahtAddFilterItem(strFilter, "Tab Files (*.tab)", "*.tab")
strInputFileName = ahtCommonFileOpenSave( _
Filter:=strFilter, OpenFile:=True, _
DialogTitle:="Please select an input file...", _
Flags:=ahtOFN_HIDEREADONLY)
DoCmd.TransferText acExportDelim, "Alibris Import specification",
"AlibrisImportTable", ""

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top