H
Hallgeir
I fill my listbox with code example found on the internet written by Zameer
Abdulla, LVLoadData.mdb. I'm not good at programming, only good at copying
code . When I click twice on the same row in the listbox it becomes
possible to edit the first column field. How can I avoid this. Appreciate any
tips. Code below:
Public Sub FillEmployees()
On Error GoTo ErrorHandler
'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 where Lastname Like '*" &
Forms!frmlistviewemployees!txtSearch1 & "*'"
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 , , "Emp ID", 1000, lvwColumnLeft
.Add , , "Salutation", 700, lvwColumnLeft
.Add , , "Last Name", 2000, lvwColumnLeft
.Add , , "First Name", 2000, lvwColumnLeft
.Add , , "Hire Date", 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!EmployeeID
lstItem.SubItems(1) = Nz(rs!TitleOfCourtesy, "N/A")
lstItem.SubItems(2) = Nz(Trim(rs!LastName))
lstItem.SubItems(3) = Nz(Trim(rs!FirstName))
lstItem.SubItems(4) = Format(rs!HireDate, "Medium Date")
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: " & Err.Description
Resume ErrorHandlerExit
End If
End Sub
Abdulla, LVLoadData.mdb. I'm not good at programming, only good at copying
code . When I click twice on the same row in the listbox it becomes
possible to edit the first column field. How can I avoid this. Appreciate any
tips. Code below:
Public Sub FillEmployees()
On Error GoTo ErrorHandler
'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 where Lastname Like '*" &
Forms!frmlistviewemployees!txtSearch1 & "*'"
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 , , "Emp ID", 1000, lvwColumnLeft
.Add , , "Salutation", 700, lvwColumnLeft
.Add , , "Last Name", 2000, lvwColumnLeft
.Add , , "First Name", 2000, lvwColumnLeft
.Add , , "Hire Date", 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!EmployeeID
lstItem.SubItems(1) = Nz(rs!TitleOfCourtesy, "N/A")
lstItem.SubItems(2) = Nz(Trim(rs!LastName))
lstItem.SubItems(3) = Nz(Trim(rs!FirstName))
lstItem.SubItems(4) = Format(rs!HireDate, "Medium Date")
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: " & Err.Description
Resume ErrorHandlerExit
End If
End Sub