ListView Code Error

oskar

Registered User.
Local time
Yesterday, 22:28
Joined
Jul 9, 2013
Messages
69
I cant find the error on the following listview code (I get error No:3265 Description:); The employees fields and form / control names are correct and when I switch to the formview I see all the column headers as they supposed to be plus I see 1 record with only the company entry

The article I follow for this lesson is here: http://www.tek-tips.com/faqs.cfm?fid=6025

Any help?
----------------------------------------------------------
Public Sub FillEmployees()
On Error GoTo ErrorHandler
'Set Reference to Microsoft DAO 3.xx Library.

'set variables
Dim rs As DAO.Recordset
Dim db As Database
Dim lstItem As ListItem
Dim strSQL As String

Set db = CurrentDb()
strSQL = "SELECT * FROM Employees"
Set rs = db.OpenRecordset(strSQL)

With Me.ListView1
'Set ListView style
.View = lvwReport
'This is not supported by ListView 5
.GridLines = True
.FullRowSelect = True
'Clear Header and ListItems
.ListItems.Clear
.ColumnHeaders.Clear
End With
'Set up column headers
With Me.ListView1.ColumnHeaders
.Add , , "ID", 700, lvwColumnLeft
.Add , , "Company", 2000, lvwColumnLeft
.Add , , "Last Name", 2000, lvwColumnLeft
.Add , , "First Name", 2000, lvwColumnLeft
.Add , , "Job Title", 1500, lvwColumnRight
End With
' Add items and subitems to list control.

rs.MoveFirst
Do Until rs.EOF
Set lstItem = Me.ListView1.ListItems.Add()
lstItem.Text = rs!ID
lstItem.SubItems(1) = rs!Company
lstItem.SubItems(2) = rs!LastName
lstItem.SubItems(3) = rs!FirstName
lstItem.SubItems(4) = rs!JobTitle
'Next row
rs.MoveNext
Loop
'close recordset
rs.Close
DoCmd.Echo True
ErrorHandlerExit:
Exit Sub
ErrorHandler:
If Err = 3021 Then ' no current record
Resume Next
Else
MsgBox "Error No:" & Err.Number & ";Description:"
Resume ErrorHandlerExit
End If

End Sub

Private Sub Form_Load()
Call FillEmployees
End Sub
 

Users who are viewing this thread

Back
Top Bottom