Select All Records on Form Checkbox

razorking

Registered User.
Local time
Today, 13:18
Joined
Aug 27, 2004
Messages
332
OK, I have a form that is in continuous forms format. It has data from an underlying table. The table and form have a checkbox (yes/no field) called - select.

I also have a list box on the form that is used to filter records. What I need to do is:
1) Filter the records (this works)
2) Set the "select" field to yes for all filtered records

I cannot figure out how to do #2 above.

I need to select all records after the filter and set the yes/no property to yes, for those records only..because most often most of the records will be desired on the report, so I want to select all and manually deselect records not wanted.

Does this make sense?
 
Run the following VBA Code from a Command Button (name: cmdMark) click event procedure after filtering the data on the Form:

Code:
Private Sub cmdMark_Click()
Dim rst As Recordset, i As Integer

Set rst = Me.RecordsetClone
i = 0
rst.MoveFirst
Do While Not rst.EOF
   i = i + 1
   rst.Edit
   If rst![FieldName] Then
       rst![FieldName] = False
   Else
       rst![FieldName] = True
   End If
   rst.Update
   rst.MoveNext
Loop
MsgBox i & " Records Marked."

rst.Close
Set rst = Nothing

End Sub

Change the [FieldName] in the Code to match to your table field name.

If you click on the Command Button, after marking the records, a second time all the records will be unmarked.
 
It works brilliantly!

Thanks so much - you have saved my life! (Ok...not quite...but thanks anyway)
 
Run the following VBA Code from a Command Button (name: cmdMark) click event procedure after filtering the data on the Form:

Code:
Private Sub cmdMark_Click()
Dim rst As Recordset, i As Integer

Set rst = Me.RecordsetClone
i = 0
rst.MoveFirst
Do While Not rst.EOF
   i = i + 1
   rst.Edit
   If rst![FieldName] Then
       rst![FieldName] = False
   Else
       rst![FieldName] = True
   End If
   rst.Update
   rst.MoveNext
Loop
MsgBox i & " Records Marked."

rst.Close
Set rst = Nothing

End Sub

Change the [FieldName] in the Code to match to your table field name.

If you click on the Command Button, after marking the records, a second time all the records will be unmarked.

I'm using Access 2007. I put above code to the checkbox on click property and it woks nicely. But when closing the form following error msg appears. Could you kindly advise how to avoid that.

<<quote>>

This record has been changed by another user since you started to editing it. if you save the record, you will overwrite the changes the other user made.

Copying the changes to the clipboard will let you look at the values the other user entered, and then paste your changes back in if you decide to make changes.

<<unquote>>
 
Run the following VBA Code from a Command Button (name: cmdMark) click event procedure after filtering the data on the Form:

Code:
Private Sub cmdMark_Click()
Dim rst As Recordset, i As Integer

Set rst = Me.RecordsetClone
i = 0
rst.MoveFirst
Do While Not rst.EOF
   i = i + 1
   rst.Edit
   If rst![FieldName] Then
       rst![FieldName] = False
   Else
       rst![FieldName] = True
   End If
   rst.Update
   rst.MoveNext
Loop
MsgBox i & " Records Marked."

rst.Close
Set rst = Nothing

End Sub

Change the [FieldName] in the Code to match to your table field name.

If you click on the Command Button, after marking the records, a second time all the records will be unmarked.

Thanks that code helped me a lot, I just added some code to the msg box, I am sharing it back as appreciation

Code:
Private Sub cmdMark_Click()
Dim rst As Recordset, i As Integer, [COLOR="Red"]checkStat As String[/COLOR]

Set rst = Me.RecordsetClone
i = 0
rst.MoveFirst
Do While Not rst.EOF
   i = i + 1
   rst.Edit
   If rst![FieldName] Then
       rst![FieldName] = False
       [COLOR="red"]checkStat = "Unselected."[/COLOR]
   Else
       rst![FieldName] = True
       [COLOR="red"]checkStat = "Selected."[/COLOR]
   End If
   rst.Update
   rst.MoveNext
Loop
MsgBox i & " Records " [COLOR="red"]& checkStat[/COLOR]

rst.Close
Set rst = Nothing

End Sub
 
ComboBox in Datasheet Veiw Form

Hello friends
I am making a form to Select Some Records and then send it to Print.

I want to use a Form in DataSheet View. Using ComboBox for Selecting a Record from thousands of records.

Upon selecting from ComboBox other 5 fields must display. I want to continue it till the required quantity of Records select.

Now this form works for Only 1 Record and then tab stop. and not going
further. the logic is like this

Select Received.DrawingNo, Received.Rev, Received.Title, Received.Type, Received.Purpose
From Received
Order BY Received.DrawingNo;

Private Sub Form_AfterUpdate()
DrawingCombo.Requery
End Sub

Why Tap stop and not going further. Where I am making mistake. Is my logic, to use DataSheet View form is correct. Please some one help.

Thanks
irsmalik
 

Attachments

guys i have a problem here what if the form still no record in it they will give me a error box so what the solution
 

Users who are viewing this thread

Back
Top Bottom