Importing from CSV file to existing data base

R

Rony

HI
Everday I receive data file FXLAD_20050515 CSV FORMAT (extension _20050515
indicates date of the file) from branch office, my Database table name is
FXLAD.

I have a form with a command button that I want to allow the user to browse
for a file to import, and then once they select the file, need to update
existing table FXLAD. (without extension of dates)

How can i do that.

Thanks in advance
 
D

Dennis

In the click event of the button try something like this
Private Sub YourButton_Click()
Dim dlgOpen As FileDialog
Dim strFile As String

Set dlgOpen = Application.FileDialog(msoFileDialogOpen)
With dlgOpen
.AllowMultiSelect = False
.Filters.Clear
.Filters.Add "All Files", "*.*", 1
.Show
End With
If dlgOpen.SelectedItems.Count = 1 Then
strFile = dlgOpen.SelectedItems(1)
DoCmd.TransferText acImportDelim, , "FXLAD", strFile, True
End If
Set dlgOpen = Nothing
End Sub
 
R

Rony

Thanks for the reply
When i patsed this code under command button and while running the following
messgae appears

Compile error
User defined type not defined

please help

Thanks
Rony
 
E

Elliot

Rony said:
HI
Everday I receive data file FXLAD_20050515 CSV FORMAT (extension _20050515
indicates date of the file) from branch office, my Database table name is
FXLAD.

I have a form with a command button that I want to allow the user to
browse
for a file to import, and then once they select the file, need to update
existing table FXLAD. (without extension of dates)

How can i do that.

Thanks in advance
 
D

Dennis

You probably have a missing reference. In the code for the form, click tools
and then references. Are there any with missing against them ?
What references do you have selected ?
What version of access are you running ?
 
R

Rony

Hi Dennis
I Checked the refernce Office object library, then it worked, How we can
find out particular reference is missing, system does not indicate which
refence is missing.

One more request.
I need to know how can i get direct to the folder .
e.g suppose the file is in folder D:\Download\fxlad_20050525

Thanks in advance
Rony
 
D

Dennis

Inside the With dlgOpen statements add the following

..InitialFileName = "D:\Download\fxlad_20050525"
 
R

Rony

Thanks Dennis, really this code helped me lot of time saving.

With tis code how can I Save as file optionn in another folder

From D:\Download\fxlad_20050525
To C:\Workfile\
Thanks for your time

Rony
 
D

Dennis

Not sure exactly but it will be something like this after you have used the
open to get your initial file name.

Set dlgOpen = Application.FileDialog(msoFileDialogSaveAs)
dlgOpen.InitialFileName = "C:\Workfile"
dlgOpen.Show
 
R

Rony

Hi Dennis
I got everthing right, but when i am within the application and run this
code, system defaults to "My documents" as default directory, However when I
First time open the application it initiates the default directory as
D:\download.

I have three csv files to download, I need the code to directly defaults to
Directory
D:\download
After -"Set dlgOpen = Application.FileDialog(msoFileDialogOpen)"
..............D:\download,
Before - "With dlgOpen"

Any hint

Thanks
Rony
 
Top