Select all CheckBoxes

B

Bob

I have a button in my header on my tabular form that will un-tick one check
box if selected is it possible to change it so it un-ticks all checkboxes on
my tabular form
Thanks for any help.....Bob

Private Sub Command19_Click()
[CbWorksheet] = "0"

End Sub
 
S

storrboy

I assume you mean in each record?
It would be faster and more efficient to run an update query and then
requery the form.
 
S

storrboy

Thanks where would I start .....Thanks Bob


If you're going to provide this ability, I personally would make two
buttons, one a Select All, one a Clear All. Each would call the same
function that would mark them as true or false depending on the
argument. Since I don't know what fields in what table need to be
affected, I can only give a guideline, you'd need to work out the
syntax for the update query.
Add the following function to the forms module.

Sub SelAllNone(Optional SelectAll As Boolean = True)
On Error Goto stoprun

Dim sqlStr As String
Dim wrk As Workspace
Dim db As Database

Set wrk=DBEngine.Workspaces(0)
Set db=CurrentDb

'Insert real query string below
sqlStr = "UPDATE [tablename] SET [FieldName] = " & SelectAll & ";"
wrk.BeginTrans
db.Execute sqlStr, dbFailOnError
wrk.CommitTrans

Exit_Here:
Set wrk=Nothing
Set db=Nothing
Exit Sub

stoprun:
Msgbox Err.Number & " - " & Err.Description
wrk.RollBack
Resume Exit_Here
End Sub

Add a SelectAll button (and if desired a Select None) button to form
and add this line to the Click event of each.

'Select All
SelAllNone True
Me.Requery

'Select None
SelAllNone False
Me.Requery

Does that help?
 
B

Bob

storrboy said:
Thanks where would I start .....Thanks Bob


If you're going to provide this ability, I personally would make two
buttons, one a Select All, one a Clear All. Each would call the same
function that would mark them as true or false depending on the
argument. Since I don't know what fields in what table need to be
affected, I can only give a guideline, you'd need to work out the
syntax for the update query.
Add the following function to the forms module.

Sub SelAllNone(Optional SelectAll As Boolean = True)
On Error Goto stoprun

Dim sqlStr As String
Dim wrk As Workspace
Dim db As Database

Set wrk=DBEngine.Workspaces(0)
Set db=CurrentDb

'Insert real query string below
sqlStr = "UPDATE [tablename] SET [FieldName] = " & SelectAll & ";"
wrk.BeginTrans
db.Execute sqlStr, dbFailOnError
wrk.CommitTrans

Exit_Here:
Set wrk=Nothing
Set db=Nothing
Exit Sub

stoprun:
Msgbox Err.Number & " - " & Err.Description
wrk.RollBack
Resume Exit_Here
End Sub

Add a SelectAll button (and if desired a Select None) button to form
and add this line to the Click event of each.

'Select All
SelAllNone True
Me.Requery

'Select None
SelAllNone False
Me.Requery

Does that help?

"Does that help?" You are a Genius, worked Brilliant thanks very much for
you help.....Bob ;)
 
B

Bob

If I have a listbox called 1stActiveHorses is there a code I can use on a
button to select (Highlight) all records in the List Box, instead of holding
shift key on fisrt and last record
Thanks Storrboy.................Bob
 
S

storrboy

If I have a listbox called 1stActiveHorses is there a code I can use on a
button to select (Highlight) all records in the List Box, instead of holding
shift key on fisrt and last record
Thanks Storrboy.................Bob


Same idea as the checkboxes.

Sub ListSelect(Optional SelAll As Boolean = True)
Dim lstItem As Long

For lstItem = 0 To Me![ListBoxName].ListCount - 1
Me![ListBoxName].Selected(lstItem) = SelAll
Next lstItem
End Sub
 
B

Bob

Does this script not have a button to select all in list box.....Thanks Bob

storrboy said:
If I have a listbox called 1stActiveHorses is there a code I can use on a
button to select (Highlight) all records in the List Box, instead of
holding
shift key on fisrt and last record
Thanks Storrboy.................Bob


Same idea as the checkboxes.

Sub ListSelect(Optional SelAll As Boolean = True)
Dim lstItem As Long

For lstItem = 0 To Me![ListBoxName].ListCount - 1
Me![ListBoxName].Selected(lstItem) = SelAll
Next lstItem
End Sub
 
S

storrboy

As I said, same idea as the checkboxes...

'Select All
ListSelect True

'Select None
ListSelect False
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top