From: Hallgeir on
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
From: Larry Linson on
I rarely, if ever, use a List Box. I prefer to use the Combo Box because it
requires less "screen real estate" -- using a Combo Box, set the Limit To
List property to Yes; then, unless you provide a NotInList event, the user
cannot edit the information in the Combo Box drop-down list. And, the
Control will not take up as much of the screen as would a List Box.

--
Larry Linson, Microsoft Office Access MVP
Co-author: "Microsoft Access Small Business Solutions", published by Wiley
Access newsgroup support is alive and well in USENET
comp.databases.ms-access


"Hallgeir" <Hallgeir(a)discussions.microsoft.com> wrote in message
news:0D11900B-3975-4BC8-BA0D-B5BC8757AC39(a)microsoft.com...
>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


From: mat on
Your listbox is an activex control; Larry didn't catch that. An Access
listbox control does not really have columns, and the issue you report
would not arise.

Many ActiveX controls let you into the properties dialog for the control
when you doubleclick in design view. There you may be able to set a
property like 'editable' or 'enable edits'. Likewise you'd be able to
set that property via code but since you're not a code hound, the
property dialog might be a better choice.

You could convert to using an Access listbox, they are pretty simple to
work with. I find listboxes to be quite useful, but I guess not everyone
does <g>.

In article <0D11900B-3975-4BC8-BA0D-B5BC8757AC39(a)microsoft.com>,
Hallgeir(a)discussions.microsoft.com says...
>
> 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


From: Stuart McCall on
"Hallgeir" <Hallgeir(a)discussions.microsoft.com> wrote in message
news:0D11900B-3975-4BC8-BA0D-B5BC8757AC39(a)microsoft.com...
>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

In your With Me.ListView1 block:

..LabelEdit = lvwManual


From: Larry Linson on
Thanks, mat. You are right... I did not realize the O.P. was talking about a
ListView, not a List Box. There's good information on TreeView and ListView
in former MVP Jeff Conrad's "Access Junkie" site, which you'll now find at
http://www.accessmvp.com/JConrad/accessjunkie.html

--
Larry Linson, Microsoft Office Access MVP
Co-author: "Microsoft Access Small Business Solutions", published by Wiley
Access newsgroup support is alive and well in USENET
comp.databases.ms-access


"mat" <mat(a)notarealdotcom.adr> wrote in message
news:MPG.266b4124edaac9399897cc(a)msnews.microsoft.com...
> Your listbox is an activex control; Larry didn't catch that. An Access
> listbox control does not really have columns, and the issue you report
> would not arise.
>
> Many ActiveX controls let you into the properties dialog for the control
> when you doubleclick in design view. There you may be able to set a
> property like 'editable' or 'enable edits'. Likewise you'd be able to
> set that property via code but since you're not a code hound, the
> property dialog might be a better choice.
>
> You could convert to using an Access listbox, they are pretty simple to
> work with. I find listboxes to be quite useful, but I guess not everyone
> does <g>.
>
> In article <0D11900B-3975-4BC8-BA0D-B5BC8757AC39(a)microsoft.com>,
> Hallgeir(a)discussions.microsoft.com says...
>>
>> 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
>
>