PDA

View Full Version : Checking 1 checkbox also checks other boxes with same criteria



demifelix
06-22-2009, 06:06 PM
Hi,

I'm new to VBA, and I have a question about checkbox in Access. I have something like below:

Row Col A Col B Checkbox
1 1 2 FALSE
2 1 1 FALSE
3 1 3 FALSE
4 1 2 FALSE
.....
100 1 3 FALSE

I would like to be able to do the following: when the checkbox in row 1 is checked, the checkbox in row 4 will also be checked instantly since the values in Col A and Col B are the same. In other words, I need to go thru all the rows, check to see if the values in Col A and B are the same, and set the checkbox value to be the same.

Any help is really much appreciated.
Thanks.
demifelix

OBP
06-23-2009, 02:57 AM
This can be achieved using a VBA RecordsetClone which you would loop through after each check box is ticked (or unticked?). It would work much faster if the Records were sorted by Column a and then Column B before working on it, because then you could exit the loop as soon as a non matching values was found.
You could even do it with the Form's Records but that would be rather slow.

Can I ask why you need to do this

demifelix
06-23-2009, 06:26 AM
Thanks for the reply. The reason I need something like this is that Col A and Col B are the locations in the warehouse, and when I put something into that location and check the box, I need to flag all other products in that same location as well.

Is there anyway you can show me some syntax/framework on how to do RecordsetClone? I'm very new to this whole VBA thing.

Thanks again.

OBP
06-23-2009, 06:49 AM
This is an example of a recordsetClone and a For/Next loop.
Dim rs As Object, count As Integer, data() As Variant, rstable As Object, db As Object

Set rs = Me.RecordsetClone
rs.Bookmark = Me.Bookmark
For count = 0 To fieldcount
data(count, 1) = rs(count).Name
Next count
rs.Close
Set rs = Nothing