Change value of selected records in Listbox

daze

Registered User.
Local time
Today, 15:14
Joined
Aug 5, 2009
Messages
61
Here is what I want to do;

I want to change value of checkbox [Zavrseno] from false to true by selecting records in Listbox [tablica] in query [isporuka po policama]

I've assigned this code on command button:


Private Sub Izdano_Click()
Dim rs As DAO.Recordset
Dim ctl As Control
Dim varItm As Variant
Set ctl = Me![tablica]
Set rs = CurrentDb.OpenRecordset("SELECT [Zavrseno] FROM [isporuka po policama]")
With ctl
For Each varItm In .ItemsSelected
rs.Edit
rs!Zavrseno = True
rs.Update
DoCmd.RunCommand acCmdRefresh
Next varItm
End With
Exit_Here:
On Error Resume Next
rs.Close
Set rs = Nothing
Exit Sub
ErrorHandler:
MsgBox err.Number & vbCrLf & err.Description
Resume Exit_Here

End Sub



The problem is that it updates only first record in listbox if ANY record is selected...

Obviously the code is wrong (or something is missing).

Help!
THNX
 
There is no automatic relationship between the recordset and the listbox loop. You would have to go to that record in the recordset on each pass (using FindFirst or something). I'd probably do this inside the loop:

CurrentDb.Execute "UPDATE TableName SET FieldName = True WHERE KeyField = " & ctl.ItemData(varItem)
 
I've been trying to make this work, and finally I got it.

Thanx for help!
 
Glad you got it working.
 

Users who are viewing this thread

Back
Top Bottom