Option Explicit
Private Sub Command1_Click()
Dim strTextLine As String
Dim intR As Integer
Dim strCat As String
Dim lngID As Long
Dim strReg As String
Dim strCity As String
intR = 1
Open "C:\Temp\YourTextFile.txt" For Input As #1
Do While Not EOF(1)
Line Input #1, strTextLine
Select Case intR
Case 1
strCat = Trim(strTextLine)
Case 2
lngID = CLng(strTextLine)
Case 3
strReg = Trim(strTextLine)
Case 4
strCity = Trim(strTextLine)
End Select
intR = intR + 1
If intR > 4 Then
Call InsertIntoDB(strCat, lngID, strReg, strCity)
strCat = ""
lngID = 0
strReg = ""
strCity = ""
intR = 1
End If
Loop
Close #1
End Sub
Private Sub InsertIntoDB(strC As String, lngI As Long, _
strR As String, strCt As String)
Dim strSQL As String
strSQL = "INSERT INTO MyTable (Category, ID, Region, City) " _
& " VALUES('" & strC & "', " & lngI & ","
If strR <> "" Then
strSQL = strSQL & "'" & strR & ", "
Else
strSQL = strSQL & "NULL, "
End If
If strCt <> "" Then
strSQL = strSQL & "'" & strCt & ")"
Else
strSQL = strSQL & "NULL)"
End If
Debug.Print strSQL
End Sub