reseting toggle boxes using macro

  • Thread starter Thread starter Argonaught
  • Start date Start date
A

Argonaught

Guest
i have toggle boxes besides each record so they can be selected to compile a report.
I want to be able to reset all the toggle boxes to there default state after i have compiled the report, at the moment i have to manualy click each one back to its original state.
I tried to alter this in vb but i have no real idea how to do that so it failed.
i created a macro and i can reset the toggle box but it will only reset the last toggle box i selected.
I did this by using set value then in the item box i put:
[Forms]![Books1form]![Include](include is the name of the toggle)
in the expresion box i put the value: false.

Any ideas how i can reset all toggle switches and not just one?

Cheers
Argonaught:confused:
 
Try this in the OnClick event of a button

Private Sub YourButton_Click()
Dim ctl As Control

For Each ctl In Me.Controls
If Left(ctl.Name, 3) = "Tog" Then
ctl.Value = False
End If
Next ctl
End Sub

"Tog" being the first 3 letters of your toggle button names.

IMO
 
The previous post will not work if you have your check boxes within the table. If this is the case, you'll have to create an Update Query. I created an example for you.

IMO
 

Attachments

this works well, except in my forms based on queries.
It does still reset the toggle but it runs the query related to the form again.
For example i have a query to select all books by one author and display them in a form, from that form i use the toggle to select the books i want in a report, i veiw the report and then go back to the form, press the [check] button to reset the toggles and it starts the author query.
Is there a way i can tell it not to do this?
 
Try changing

DoCmd.Requery

to

DoCmd.ShowAllRecords

from the code behind the button

IMO
 
Can you post the code thats behind the button, or post a stripped down version of your db and I'll take a look for you

IMO
 
ive attached a zipped version of my db, its just a cut down version but the author form, will run a query on whatever you enter in book form, the hammer over the post it note colum is the reset for the toggle.
The post it note at the top of the form puts the selections into a report.

bear in mind ive only been doing access for a few days so it will probably look very rough and messy to you, so i appologise in advance.

Cheers Argonaught
 

Attachments

Ok, The first thing you'll need to do is split your tables (Authors and Books) and link them with a one to many relationship. Have a search in the forum for Nomalization. You could then use an unbound combobox on your main form to select the Authors, which would return all the books related to that Author. This would save having to open the form from a Query and the code I sent to deselect the toggle buttons would work. The reason it reopens the query is because your form is based on having to enter the Authors Name as criteria for it to open.

Hope this helps, post back if you need more help

IMO
 
Last edited:

Users who are viewing this thread

Back
Top Bottom