hgus393
Registered User.
- Local time
- Today, 10:00
- Joined
- Jan 27, 2009
- Messages
- 83
Hi all,
I have serveral files that are stored daily in a directory with a filename that is always constant and a variable suffix that is the date. Well I am trying to import the file into a table in Access but I have encountered some difficulties, before that here is the code:
My trouble here is that I don't know the actual length of the value rs.value it can be below zero, above zero it can be 1 or it can be 50 billion. My question is is there is a way I can trap this?
Bob
I have serveral files that are stored daily in a directory with a filename that is always constant and a variable suffix that is the date. Well I am trying to import the file into a table in Access but I have encountered some difficulties, before that here is the code:
Code:
Sub GetRate()
Dim DateNr As Date
DoCmd.Hourglass True
Dim path As String
Dim s As String
Dim MyFile As String
Dim rs As Recordset
Dim sql As String
DateNr = InputBox("Date", "Date")
path = "C:\temp\Bob" & Format(CStr(DateNr), "YYYY-MM-DD") & ".txt"
MyFile = Dir(path)
If MyFile = "" Then
MsgBox path & " Missing!", , "File is missing"
DoCmd.Hourglass False
Exit Sub
End If
CurrentDb.Execute "DELETE * FROM Rates", dbFailOnError
Set rs = CurrentDb.OpenRecordset("Rates") 'Output-table
Close #1
Open path For Input Lock Read As #1
Do While Not EOF(1)
Line Input #1, s
rs.AddNew
rs!Currency= Mid(s, 1, 3)
rs!Value = Mid(s, 4, 9)
rs!Covar = Mid(s, 13, 5)
rs.Update
Loop
Close #1
DoCmd.Hourglass False
End Sub
Bob