Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

tickboxes for a listbox control

Status
Not open for further replies.

galorin

MIS
Nov 22, 2007
154
GB
I use the following code to generate a listbox populated with item and version info. I want to provide a tickbox that I can use to say that a new version has been issued, but I don't know how to do it, and can't find where it is addressed in VBA.

I am coding on office Pro 2003

Code:
Private Sub popCurItems()
Dim lstItem As ListItem
Dim item() As String
Dim i As Integer
Dim FirstName As String
Dim LastName As String
Dim Company As String

'next 3 lines will be replaced with a person ID number
FirstName = Forms!People.CntName.column(1) 
LastName = Forms!People.CntName.column(2)
Company = Forms!Company.Company

Call connectDB 'connection strings to connect to MySQL

SQLout = "select count(Item) from ItemVer where Item not like 'Dongle' and Item not like 'Not Issued'"

Call getData 'gets number of tracked items

ReDim item(rst.Fields(0) - 1)


SQLout = "select Item from ItemVer where Item not like 'dongle' and Item not like 'Not Issued';"

Call getData 'gets all item names except those where multiple items are issued and tracked

i = 0

If Not rst.EOF Then
 rst.MoveFirst
 Do
   item(i) = rst.Fields(0)
   i = i + 1
   rst.MoveNext
 Loop Until rst.EOF                                                 
End If

'format my listbox (CurItems)
With Me.CurItems
 .View = lvwReport
 .GridLines = True
 .FullRowSelect = True
 .ListItems.Clear
 .ColumnHeaders.Clear
 .Width = 4800
End With

'Place column headers
With Me.CurItems.ColumnHeaders
 .Add , , "Item Name", 3000, lvwColumnLeft
 .Add , , "Issued Version", 1500, lvwColumnRight
 .Add , , "Issue Code", 0, lvwColumnRight
End With

For i = 0 To UBound(item)
 SQLout = ""
 SQLout = SQLout & "call IsCurrent('" & FirstName & "','" & LastName
 SQLout = SQLout & "','" & Company & "','" & item(i) & "');"
 
 Call getData 'subroutine to grab data from MySQL stored procedure

 rst.MoveFirst
 Do Until rst.EOF
  Set lstItem = Me.CurItems.ListItems.Add()
  lstItem.Text = Nz(item(i))
  lstItem.SubItems(1) = Nz(rst.Fields(1))
  lstItem.SubItems(2) = Nz(rst.Fields(0))
  rst.MoveNext
 Loop
Next i

cn.CLose
Call format 'calls a sub to do conditional formatting off of  "Issue Code"

End Sub
 
galorin,
I know MS updated the ListBox control in Access 2003 (adding functionality like the [tt]Add[/tt] method, and apparently [tt]View[/tt]) but I don't believe [tt]ListStyle[/tt] made the cut, but you could try.

[tab][tt].ListStyle = fmListStyleOption[/tt]

If that doesn't work you could use the MSForms (2.0) Listbox.

Hope this helps,
CMP

[small]For the best results do what I'm thinking, not what I'm saying.[/small]
(GMT-07:00) Mountain Time (US & Canada)
 
The code shown here is for "ListView" not for "ListBox"
ListView has chekboxes option(I think it is available from Version 6)
try
Code:
With Me.CurItems
 .View = lvwReport
 .GridLines = True
 .FullRowSelect = True
 .ListItems.Clear
 .ColumnHeaders.Clear
 .Width = 4800
 [b].Checkboxes = True[/b]

End With

You can set it from the design view too



________________________________________________________
Zameer Abdulla
Help to find Missing people
 
Perfect, that was simple enough. Now, because intellisense doesn't pick up anything to do with my listview, where can I find the documentation for the properties associated with this control?

Also, how do I deal with the tickboxes, do they fall under a .Selected = True or some such?
 
I have learned it from VB6
Here is a way to see the properties
Just type below in the code window. after the "lvw." itellisense will help you.
Code:
Dim lvw As New ListView
lvw.


________________________________________________________
Zameer Abdulla
Help to find Missing people
 
Yes to get the checked items list
Code:
For nI = Me.ListView0.ListItems.Count To 1 Step -1
    If Me.ListView0.ListItems.Item(nI).Checked = True Then
    Debug.Print Me.ListView0.ListItems.Item(nI).Text 
    End If
    If Me.ListView0.ListItems.Count = 0 Then Exit For
Next
And check this link too for more details about properties.

________________________________________________________
Zameer Abdulla
Help to find Missing people
 
Ok, been working with the ListView code above, but it is a multi-column listview. Follows is the code I use to generate my listview from a result set, garnered from a MySQL stored procedure(Set to change to using numeric identities). the Item() array is filled with item names to feed the stored procedure (again to be changed to numerics once this is working)

Code:
For I = 0 To UBound(item)
 SQLout = ""
 SQLout = SQLout & "call IsCurrent('" & FirstName & "','" & LastName
 SQLout = SQLout & "','" & Company & "','" & item(I) & "');"
 
 Call getData

 rst.MoveFirst
 Do Until rst.EOF
  Set lstItem = Me.CurItems.ListItems.Add()
  lstItem.Text = Nz(item(I))
  lstItem.SubItems(1) = Nz(rst.Fields(1))
  lstItem.SubItems(2) = Nz(rst.Fields(0))
  rst.MoveNext
 Loop
Next I

I can get the value in lstItem.Text for each selected entry, but not the subitems. How do I get the value in SubItem(1) as that is the data I need to get at for one part of my code?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top