Originally Posted by
Declen
No. I want to select up to 6 elements from Elements table and set them all as Done.
Okay, that's fairly clear-cut requirement. Several ways to code this.
This could probably be done entirely with a parameterized query object (I avoid parameterized queries). It could look like:
UPDATE Elements SET Elements.Done = True
WHERE (((Elements.El)=Nz([Forms]![Set Elements to discovered]![Kombinationsfeld0],"") Or (Elements.El)=Nz([Forms]![Set Elements to discovered]![Kombinationsfeld10],"") Or (Elements.El)=Nz([Forms]![Set Elements to discovered]![Kombinationsfeld12],"") Or (Elements.El)=Nz([Forms]![Set Elements to discovered]![Kombinationsfeld14],"") Or (Elements.El)=Nz([Forms]![Set Elements to discovered]![Kombinationsfeld16],"") Or (Elements.El)=Nz([Forms]![Set Elements to discovered]![Kombinationsfeld18],"")));
And then could code macro or VBA to call parameterized query object (I don't use macros).
Options in VBA not using parameterized query.
Have VBA for each combobox AfterUpdate event calling a Sub that runs SQL Update. Example showing one combobox, change references as necessary for the others:
Code:
Private Sub Kombinationsfeld0_AfterUpdate()
SetDone Me.Kombinationsfeld0
End Sub
Sub SetDone(strE)
CurrentDb.Execute "UPDATE Elements SET Done=True WHERE El='" & Replace(strE, "'", "''") & "'"
End Sub
Another approach is to have function running the SQL:
Code:
Function SetDone(strE)
CurrentDb.Execute "UPDATE Elements SET Done=True WHERE El='" & Replace(strE, "'", "''") & "'"
End Function
Now in the combobox AfterUpdate property: =SetDone([Kombinationsfeld0])
Again, change combobox reference as necessary.
Note in the VBA use of Replace() function to deal with possible apostrophe.