Howdy all,
I've been working on adding check boxes to my ListView control. I thought it would be a bit more straight forward. Below is my code. I'm also not sure why I'm only getting 1 line of data because when I loop through the code it appears to give me the correct data but when the form opens there's only 1 line of data. Any help would be wonderful!
Option Compare Database
Private Sub Form_Open(Cancel As Integer)
Dim lstview As ListView
Dim db As Database
Dim rst As DAO.Recordset
Dim strSQL As String
Dim lstitem As ListItem
Set db = CurrentDb
strSQL = "SELECT * FROM tbltest;"
Set lstview = Me.lstview.Object
With lstview
.View = lvwReport
.FullRowSelect = True
.Checkboxes = True
.AllowColumnReorder = True
End With
With lstview.ColumnHeaders
.Add , , "INCR", 0
.Add , , "Name", 1500, lvwColumnLeft
.Add , , "Male", 1500, lvwColumnCenter
.Add , , "Female", 1500, lvwcolumcenter
.Add , , "Over 60", 1500, lvwcolumcenter
End With
Set rst = db.OpenRecordset(strSQL)
rst.MoveFirst
Set lstitem = Me.lstview.ListItems.Add()
Do Until rst.EOF
lstitem.Text = Nz(rst![INCR])
lstitem.SubItems(1) = Nz(rst![Name])
lstitem.SubItems(2) = IIf(Nz(rst![Male]) = True, lstitem.Checked = True, lstitem.Checked = False)
lstitem.SubItems(3) = IIf(Nz(rst![Female]) = True, lstitem.Checked = True, lstitem.Checked = False)
lstitem.SubItems(4) = IIf(Nz(rst![Over60]) = True, lstitem.Checked = True, lstitem.Checked = False)
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
Set db = Nothing
DoCmd.Echo True
End Sub
I've been working on adding check boxes to my ListView control. I thought it would be a bit more straight forward. Below is my code. I'm also not sure why I'm only getting 1 line of data because when I loop through the code it appears to give me the correct data but when the form opens there's only 1 line of data. Any help would be wonderful!
Option Compare Database
Private Sub Form_Open(Cancel As Integer)
Dim lstview As ListView
Dim db As Database
Dim rst As DAO.Recordset
Dim strSQL As String
Dim lstitem As ListItem
Set db = CurrentDb
strSQL = "SELECT * FROM tbltest;"
Set lstview = Me.lstview.Object
With lstview
.View = lvwReport
.FullRowSelect = True
.Checkboxes = True
.AllowColumnReorder = True
End With
With lstview.ColumnHeaders
.Add , , "INCR", 0
.Add , , "Name", 1500, lvwColumnLeft
.Add , , "Male", 1500, lvwColumnCenter
.Add , , "Female", 1500, lvwcolumcenter
.Add , , "Over 60", 1500, lvwcolumcenter
End With
Set rst = db.OpenRecordset(strSQL)
rst.MoveFirst
Set lstitem = Me.lstview.ListItems.Add()
Do Until rst.EOF
lstitem.Text = Nz(rst![INCR])
lstitem.SubItems(1) = Nz(rst![Name])
lstitem.SubItems(2) = IIf(Nz(rst![Male]) = True, lstitem.Checked = True, lstitem.Checked = False)
lstitem.SubItems(3) = IIf(Nz(rst![Female]) = True, lstitem.Checked = True, lstitem.Checked = False)
lstitem.SubItems(4) = IIf(Nz(rst![Over60]) = True, lstitem.Checked = True, lstitem.Checked = False)
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
Set db = Nothing
DoCmd.Echo True
End Sub