When i run my code below, it will do nothing because of the line: "If RS.Fields(0) <> Null Then". But if i take that if statement out, the msgbox will print out the data from the excel file. So i dont understand why it says its null one time but not another. i need to check for nulls for when it reaches the end of collumns or rows.
Dim filepath As String
Dim r As Integer, c As Integer
filepath = txtfile.Text
r = 0
c = 0
Dim CONN As ADODB.Connection
Dim RS As ADODB.Recordset
Set CONN = New ADODB.Connection
Set RS = New ADODB.Recordset
CONN.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & filepath & ";" & _
"Extended Properties=""Excel 8.0;HDR=Yes"""
RS.Open "SELECT * FROM [Sheet1$]", CONN
RS.MoveFirst
lstTable.Col = 0
lstTable.Row = 0
Do Until RS.EOF
lstTable.Col = c
lstTable.Row = r
If (c = c + 1) > lstTable.Cols Then
c = 0
r = r + 1
Else
c = c + 1
End If
If RS.Fields(0) <> Null Then
lstTable.Text = RS.Fields(0)
MsgBox RS.Fields(1)
Else
lstTable.Text = "Robot"
End If
RS.MoveNext
Loop
Dim filepath As String
Dim r As Integer, c As Integer
filepath = txtfile.Text
r = 0
c = 0
Dim CONN As ADODB.Connection
Dim RS As ADODB.Recordset
Set CONN = New ADODB.Connection
Set RS = New ADODB.Recordset
CONN.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & filepath & ";" & _
"Extended Properties=""Excel 8.0;HDR=Yes"""
RS.Open "SELECT * FROM [Sheet1$]", CONN
RS.MoveFirst
lstTable.Col = 0
lstTable.Row = 0
Do Until RS.EOF
lstTable.Col = c
lstTable.Row = r
If (c = c + 1) > lstTable.Cols Then
c = 0
r = r + 1
Else
c = c + 1
End If
If RS.Fields(0) <> Null Then
lstTable.Text = RS.Fields(0)
MsgBox RS.Fields(1)
Else
lstTable.Text = "Robot"
End If
RS.MoveNext
Loop