How to avoid error Invalid use of null in Visual Basic 6
How to Use Do While orSequential reading in database
'Declaration
ConstmCon ="Provider=MSDASQL.1;Persist Security Info=False;Data Source=ipayroll"
'Note : Please change the connection string to make it work, this is my sample connection string in payroll system I developed.
Sub Load_Employee()
On Error GoTo errHandler
Dim rs1 As New ADODB.Recordset
Dim mSQL As String
cboName.Clear
With rs1
mSQL = "Select FirstName,FirstName,MI From Employee Where Status <> 'Inactive' order by LastName"
.Open mSQL, mCon, adOpenDynamic, adLockReadOnly
Do While Not .EOF
If (not isnull(!LastName) or !LastName <> "") And(not isnull(!FirstName) or !FirstName <> "")then
Ifnot isnull(!MI) or !MI <> "" then 'sometime Middle name is optional
cboName.AddItem !LastName & "," & !FirstName & " " & Right(!MI,1) & "."
Else 'Middle name is null or blank
cboName.AddItem !LastName & "," & !FirstName
End If
End if
.MoveNext 'Move point to next record
Loop
.Close 'Close database after using
End With
Exit Sub
errHandler:
MsgBox Err.Number & Err.Description
End Sub