XLEAccessGuru
XLEGuru
- Local time
- Today, 17:07
- Joined
- Nov 17, 2006
- Messages
- 65
I've seen plenty of posts that tell me how to enumerate selected list box items, but none that advise on enumerating the bound column for ALL items in a list box. Access VBA help says "You can use the ListCount property to determine the number of rows in the list box, and then use the ItemData property to return the data for the bound column in each row."
Based on that, I started with the code below, but so far, 'stCriteria' is only returning selected items in the list box. What I need to do, as you can see below, is update the Status field in all records in a separate table that match ALL of the (invisible column) Profile ID numbers from the List Box to "Canceled".
I thought that the 'ItemsSelected' property was what enumerates the selected items in a list box, not 'ItemData', but it seems like ItemData is only returning selected items as well.
What am I not getting here?
Based on that, I started with the code below, but so far, 'stCriteria' is only returning selected items in the list box. What I need to do, as you can see below, is update the Status field in all records in a separate table that match ALL of the (invisible column) Profile ID numbers from the List Box to "Canceled".
I thought that the 'ItemsSelected' property was what enumerates the selected items in a list box, not 'ItemData', but it seems like ItemData is only returning selected items as well.
What am I not getting here?

Code:
Private Sub cmdCancel_Click()
On Error GoTo ErrHandle
Dim stSQL As String
Dim db As DAO.Database
Dim stCriteria As String
Dim x As Integer, y As Integer
Set db = Application.CurrentDb
If lstErrors.ListCount > 1 Then
x = Me.lstErrors.ListCount
y = 0
'build criteria string containing ProfileID numbers
For y = 0 To x
If Len(stCriteria) = 0 Then
stCriteria = Me.lstErrors.ItemData(y)
Else
stCriteria = stCriteria & ", " & Me.lstErrors.ItemData(y)
End If
y = y + 1
Next y
Debug.Print stCriteria
'build SQL string
stSQL = "UPDATE tblValidation SET tblValidation.Status = 'Canceled' " _
& "WHERE (((tblValidation.ProfileRecordID) In (" & stCriteria & ")) AND " _
& "((tblValidation.Pass)=" & iPass & "));"
db.Execute (stSQL) 'execute sql string (updates) all validation records in current pass to Canceled
iPass = iPass + 1 'used to update 'Pass' field in validation table to count # times validation
'is run for a single dataset
End If
DoCmd.Close acForm, "frmValidationReport"
Set db = Nothing
Exit_ErrHandle:
Exit Sub
ErrHandle:
MsgBox Err.Description, vbCritical, "Error: " & Err.Number
Resume Exit_ErrHandle
End Sub