User Selected File won't import into table

T

TexasStar

I have a simple form with 2 buttons and text box. When the user clicks
the "Select File" button this allows them to browse their hard drive
and select a csv file. The patch to the csv file is in the text box.
The second button is "Import File" which the user would click and
import the data into a table called PDS_Import.

I am getting errors when the users tries to Import the data into the
table.

This is the code that allows the user to select a file from their hard
drive. This seems to work and returns the path into a textbox named
"File2"
_________
Private Sub SelectFile_Click()
'Use file open dialog to select file
On Error GoTo ErrorHandler
Me.File2 = OpenFile(Me.File2)

GoTo Done
ErrorHandler:
MsgBox "Error: " & Err.Description & " (" & Err.Number & ")"

Done:
Exit Sub

End Sub
___________



This ImportFile function is what seems to be the problem.
_______________________
Private Sub FileImport_Click()
Dim stringPathFile As String, strFile As String, strPath As String,
strSpec As String
Dim strTable As String, ynFieldName As Boolean
strPathFile = Me.File2
strTable = "PDS_Import"

ynFieldName = True

DoCmd.TransferText acImportDelim, strTable, strPathFile, ynFieldName

End Sub
___________________________

If anyone could help me out it would be greatly appreciated. I think
it might be something simple but I just can't catch what the problem
is and why I can't get the import function to work. Thank you for any
advice or help you can provide.
 
T

TexasStar

Does Me.File2 contain the full path to the file, or just the file name?

It contains the full path. File2 is the name of the text box which is
holding the full path. Example: C:\wrg\114_6_2.csv is what is in the
text box after selecting a file.
 
D

Douglas J. Steele

TexasStar said:
It contains the full path. File2 is the name of the text box which is
holding the full path. Example: C:\wrg\114_6_2.csv is what is in the
text box after selecting a file.

What problem are you encountering?
 
T

TexasStar

What problem are you encountering?

This is the full error it gives after clicking on the Imort File
button.

___
Run-time error '3011;'
The Microsoft Jet Database engine could not find the object '-1.txt'.
Make sure the object exsists and that you spell its name and the path
name correctly.
___
 
D

Douglas J. Steele

TexasStar said:
This is the full error it gives after clicking on the Imort File
button.

___
Run-time error '3011;'
The Microsoft Jet Database engine could not find the object '-1.txt'.
Make sure the object exsists and that you spell its name and the path
name correctly.
___

Your call to the TransferText method is incorrect.

You've got:

DoCmd.TransferText acImportDelim, strTable, strPathFile, ynFieldName

The 2nd argument (where you have strTable) is supposed to be the name of the
specification you want to use for the import.

If you don't have a specification name, you can leave it blank:

DoCmd.TransferText acImportDelim, , strTable, strPathFile, ynFieldName
 
T

TexasStar

Your call to the TransferText method is incorrect.

You've got:

DoCmd.TransferText acImportDelim, strTable, strPathFile, ynFieldName

The 2nd argument (where you have strTable) is supposed to be the name of the
specification you want to use for the import.

If you don't have a specification name, you can leave it blank:

DoCmd.TransferText acImportDelim, , strTable, strPathFile, ynFieldName

--
Doug Steele, Microsoft Access MVPhttp://I.Am/DougSteele
(no e-mails, please!)- Hide quoted text -

- Show quoted text -

You are 100% right! Thank you very much for your assistance. I'm new
to this vb/access stuff so it really helps being able to go to the
pros! Again, thank you for your assistance and knowledge!
 

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