Hi Forum members
I'm not a expert vba programmer and I'm trying to adapt belowe code on my db in order to import in one table multiple files in the directory that coincide to those prompted dates. but code stop on red row (run time error 13 type mismatch).
Please could anyone help me
Thanking in advance
------------------------------------------------------
Private Sub Import_Click()
Dim stDate, edDate As Date
Dim myConvtName As Date
'Prompt for the START and END import dates
stDate = InputBox("What is the START DATE for EXT import?", "START DATE")
edDate = InputBox("What is the END DATE for EXT import?", "END DATE")
myDName = "C:\Users\ti20935\Desktop\MPS\MPS761\"
myFName = Dir(myDName, vbNormal)
'Loop through directory
Do While myFName <> ""
'Check current file - if it is between stDate and edDate import file
LatestFile7 = myFName7
'Check current file - if it is between stDate and edDate import file
myConvtName = Mid(LatestFile, 25, 2) & "/" & Mid(LatestFile, 27, 2) & "/" & Mid(LatestFile, 23, 2)
If myConvtName <= edDate Then
If myConvtName >= stDate Then
DoCmd.TransferText acImportDelim, "Import-MPS", "Dati_MPS_Foerster", myDName & LatestFile, True
Else
'Do nothing
End If
Else
'Do nothing
End If
myFName = Dir
Loop
MsgBox "Data has been imported into the Dati_MPS_Foerster"
End Sub
I'm not a expert vba programmer and I'm trying to adapt belowe code on my db in order to import in one table multiple files in the directory that coincide to those prompted dates. but code stop on red row (run time error 13 type mismatch).
Please could anyone help me
Thanking in advance
------------------------------------------------------
Private Sub Import_Click()
Dim stDate, edDate As Date
Dim myConvtName As Date
'Prompt for the START and END import dates
stDate = InputBox("What is the START DATE for EXT import?", "START DATE")
edDate = InputBox("What is the END DATE for EXT import?", "END DATE")
myDName = "C:\Users\ti20935\Desktop\MPS\MPS761\"
myFName = Dir(myDName, vbNormal)
'Loop through directory
Do While myFName <> ""
'Check current file - if it is between stDate and edDate import file
LatestFile7 = myFName7
'Check current file - if it is between stDate and edDate import file
myConvtName = Mid(LatestFile, 25, 2) & "/" & Mid(LatestFile, 27, 2) & "/" & Mid(LatestFile, 23, 2)
If myConvtName <= edDate Then
If myConvtName >= stDate Then
DoCmd.TransferText acImportDelim, "Import-MPS", "Dati_MPS_Foerster", myDName & LatestFile, True
Else
'Do nothing
End If
Else
'Do nothing
End If
myFName = Dir
Loop
MsgBox "Data has been imported into the Dati_MPS_Foerster"
End Sub