mfaqueiroz
Registered User.
- Local time
- Today, 15:25
- Joined
- Sep 30, 2015
- Messages
- 125
Hi everyone
I want to do one vba module that prompt the user to select the CSV file that i want to extract to one table in my DataBase.
I'm trying to write this code, but it only works with xls files...could you please help me to understand what i'm doing wrong..?
MODULE:
Function selectFile()
Dim fd As FileDialog, FileName As String
On Error GoTo ErrorHandler
Set fd = Application.FileDialog(msoFileDialogFilePicker)
fd.AllowMultiSelect = False
If fd.Show = True Then
If fd.SelectedItems(1) <> vbNullString Then
FileName = fd.SelectedItems(1)
End If
Else
End
End If
selectFile = FileName
Set fd = Nothing
Exit Function
ErrorHandler:
Set fd = Nothing
MsgBox "Error " & Err & ": " & Error(Err)
End Function
FORM
Private Sub cmdImport_Click()
'---------TAB 1
'Unset warnings
DoCmd.SetWarnings False
'SQL apaga
DoCmd.RunSQL "DELETE * FROM Tab1"
MsgBox "Select Tab1"
'Import
oApp.DoCmd.TransferText acImportDelim, , "Tab1", selectFile, False
'Confirmação
MsgBox "Os dados da Tabela de Instalações foram importados com sucesso"
DoCmd.SetWarnings True
End Sub
I really appreciate your help
!
I want to do one vba module that prompt the user to select the CSV file that i want to extract to one table in my DataBase.
I'm trying to write this code, but it only works with xls files...could you please help me to understand what i'm doing wrong..?
MODULE:
Function selectFile()
Dim fd As FileDialog, FileName As String
On Error GoTo ErrorHandler
Set fd = Application.FileDialog(msoFileDialogFilePicker)
fd.AllowMultiSelect = False
If fd.Show = True Then
If fd.SelectedItems(1) <> vbNullString Then
FileName = fd.SelectedItems(1)
End If
Else
End
End If
selectFile = FileName
Set fd = Nothing
Exit Function
ErrorHandler:
Set fd = Nothing
MsgBox "Error " & Err & ": " & Error(Err)
End Function
FORM
Private Sub cmdImport_Click()
'---------TAB 1
'Unset warnings
DoCmd.SetWarnings False
'SQL apaga
DoCmd.RunSQL "DELETE * FROM Tab1"
MsgBox "Select Tab1"
'Import
oApp.DoCmd.TransferText acImportDelim, , "Tab1", selectFile, False
'Confirmação
MsgBox "Os dados da Tabela de Instalações foram importados com sucesso"
DoCmd.SetWarnings True
End Sub
I really appreciate your help
!