Private Sub cmdUpdate_Click()
On Error GoTo Err_Handler
Dim varItem As Variant 'Selected items
Dim strCriteria As String, strSQL As String
Dim lngLen As Integer
Dim response
strCriteria = ""
strSQL = ""
'If no items selected, show a message that none selected
If Me.List9.ItemsSelected.Count = 0 Then
MsgBox "You have not selected any images", vbExclamation, "Error"
Else
'Ask user to confirm they want to update selected records
response = MsgBox("You have selected " & Me.List9.ItemsSelected.Count & " records to update." & vbNewLine & vbNewLine & "Are you sure you want to continue?" & vbNewLine & vbNewLine & "Note: this operation cannot be undone.", vbYesNo, "Update?")
If response = vbYes Then
'Loop through the ItemsSelected in the list box.
With Me.List9
For Each varItem In .ItemsSelected
If Not IsNull(varItem) Then
'Build up the filter from the bound column (hidden).
strCriteria = strCriteria & "'" & .ItemData(varItem) & "', " '& .Column(1, varItem)
End If
Next
End With
strCriteria = Left(strCriteria, Len(strCriteria) - 2)
strSQL = "UPDATE tblImage SET tblImage.strImageName = '" & strUpdateText & "' WHERE (((tblImage.strImageRef) In (" & strCriteria & ")));"
(" & strCriteria & ")));"
Debug.Print strSQL
DoCmd.RunSQL strSQL
response = MsgBox("Do you want to keep the items selected in the list?", vbYesNo, "Keep Selected?")
If response = vbYes Then
'Do nothing
Else
Call ClearList(Forms!frmimagedisplay!List9)
End If
Else
'Do nothing
End If
End If
Exit_Handler:
Exit Sub
Err_Handler:
If Err.Number <> 2501 Then 'Ignore "Report cancelled" error.
MsgBox "Error " & Err.Number & " - " & Err.Description, , "cmdPreview_Click"
End If
Resume Exit_Handler
End Sub