Recordset/Line Input Problem

W

Wendy

Hi

I am importing data from a text file into a table using the Line Input #
command to read the file.

Is there some code which would convert this to vb:-

If Date&"/"&Month&"/"Year is not numeric go get the next text line and do
not write anything into the table via the recordset?

The reason the date is like that is I'm having to extract it out of a text
string and turn it from MMDDYY to DDMMYY format.

Thanks

Wendy
 
D

Douglas J Steele

Well, Date & "/" & Month & "/" & Year will never be numeric, since you're
concatenating text characters into it, but I assume you meant if that's a
valid date.

Dim intFile As Integer
Dim strFile As String
Dim strBuffer As String
Dim strDate as String
Dim strMonth As String
Dim strYear As String

strFile = "..."

intFile = FreeFile
Open strFile For Input As #intFile
Do While EOF(intFile) = False
Line Input #intFile, strBuffer
'
' your code to split into Date, Month and Year
'
If IsDate(strDate & "/" & strMonth & "/" & strYear) Then
'
' your code to write to the table
'
End If
Loop

Close #intFile

Note that I renamed your variables from Date, Month and Year: those are all
reserved words, and should never be used for your own objects.
 
W

Wendy

Thanks, that works a treat.

Wendy


Douglas J Steele said:
Well, Date & "/" & Month & "/" & Year will never be numeric, since you're
concatenating text characters into it, but I assume you meant if that's a
valid date.

Dim intFile As Integer
Dim strFile As String
Dim strBuffer As String
Dim strDate as String
Dim strMonth As String
Dim strYear As String

strFile = "..."

intFile = FreeFile
Open strFile For Input As #intFile
Do While EOF(intFile) = False
Line Input #intFile, strBuffer
'
' your code to split into Date, Month and Year
'
If IsDate(strDate & "/" & strMonth & "/" & strYear) Then
'
' your code to write to the table
'
End If
Loop

Close #intFile

Note that I renamed your variables from Date, Month and Year: those are all
reserved words, and should never be used for your own objects.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top