stallzy123
New member
- Local time
- Today, 18:27
- Joined
- Apr 16, 2013
- Messages
- 9
Hi all,
I'm new to the forum and relatively new to access programming. I've got a real headache with opening file dialog to import a text file.
What I'm trying to achieve is to write code to import several text files where the suffix of the filename changes daily due to run dates/times, e.g. table_mapping_20130121_1500.csv.
Problem is I keep getting type mismatches even though the file I'm using to test the import is the same file I manually imported and created the import specification with.
Also, my debug print of the file dialog is creating an error too.
Any help would be greatly appreciated.
Here's the code I'm using (please disregard the function as I've not completely finished developing this as I've been stuck trying to get the import to work!)
Thanks,
S.
I'm new to the forum and relatively new to access programming. I've got a real headache with opening file dialog to import a text file.
What I'm trying to achieve is to write code to import several text files where the suffix of the filename changes daily due to run dates/times, e.g. table_mapping_20130121_1500.csv.
Problem is I keep getting type mismatches even though the file I'm using to test the import is the same file I manually imported and created the import specification with.
Also, my debug print of the file dialog is creating an error too.
Any help would be greatly appreciated.
Here's the code I'm using (please disregard the function as I've not completely finished developing this as I've been stuck trying to get the import to work!)
Code:
Sub Import_files_Click()
Dim fd As Object
Dim strFilter As String
'Dim lngItems As Long
Dim table_array(20) As String 'An array containing the names of the tables with imported data
Dim counter As Integer 'Used as a counter in the For loop
If fProceed = True Then
table_array(1) = "asl_mapping"
table_array(2) = "collected_liabilities"
table_array(3) = "dynamic_fof"
table_array(4) = "dynamic_fund"
table_array(5) = "dynamic_previous_price_series"
table_array(6) = "dynamic_series"
table_array(7) = "efm_emx_data"
table_array(8) = "efm_fund_manager"
table_array(9) = "efm_static"
table_array(10) = "fof_holding_transactions"
table_array(11) = "fof_inflight_trades"
table_array(12) = "life_mapping"
table_array(13) = "reconciliation"
table_array(14) = "static_base"
table_array(15) = "static_box_rules"
table_array(16) = "static_calendar"
table_array(17) = "static_feeder_funds"
table_array(18) = "static_feeder_series"
table_array(19) = "static_fof"
table_array(20) = "static_series"
'table_array(21) = "HIPO1"
'table_array(22) = "FSVALU"
'table_array(23) = "HIPO3"
'table_array(24) = "HIPO4"
'table_array(25) = "HIPO5"
For counter = 1 To 20 'amend number here!
Const msoFileDialogOpen As Long = 3
Const msoFileDialogViewDetails As Long = 2
Set fd = FileDialog(msoFileDialogOpen)
With fd
.AllowMultiSelect = False
.InitialView = msoFileDialogViewDetails
.InitialFileName = "X:\Data\Current"
.Title = "Open " & table_array(counter) & " current data"
.Filters.Clear
.Filters.Add "All Files", "*.*"
.Show
End With
Debug.Print fd.SelectedItem
DoCmd.TransferText acImportDelim, "Import-" & table_array(counter), table_array(counter), fd.SelectedItem.Count, False
Next counter
MsgBox "Current data loaded", vbInformation
Else
MsgBox "Some files weren't empty or deleted. Please check", vbCritical
End If
Thanks,
S.