Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Toggle button constanly depressed

Status
Not open for further replies.

handlebarry

Technical User
Dec 21, 2004
118
GB
I'm looking for a way to cheer up a toggle button (ok bad pun)

Anyway, I have a group of toggle buttons that apply filters to a form. However if the filter query produces no results (e.g the dec 2005 filter) then the toggle gets stuck in the down position.

(Also I'm not sure if my method is correct/best solution). Any advise appreciated


Private Sub ToggleJan_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)

DoCmd.ApplyFilter "Query Contracts Jan"
Me.grpMonth = 1

End Sub
 
Groups are normally handled in the frame's AfterUpdate() event, not the MouseDown() event of the controls. Something like this:
Code:
Private Sub groupMonth_AfterUpdate()

  Select Case groupMonth.Value
    Case 1   [green]'Jan[/green]
      DoCmd.ApplyFilter "Query Contracts Jan"
    Case 2   [green]'Feb[/green]
      DoCmd.ApplyFilter "Query Contracts Feb"
    Case 3   [green]'Mar[/green]
      DoCmd.ApplyFilter "Query Contracts Mar"    
    Case 4   [green]'Apr[/green]
      DoCmd.ApplyFilter "Query Contracts Apr"    
    Case 5   [green]'May[/green]
       DoCmd.ApplyFilter "Query Contracts May"   
    Case 6   [green]'Jun[/green]
       DoCmd.ApplyFilter "Query Contracts Jun"   

    <...etc...>

  End Select
  
  If Me.RecordsetClone.RecordCount = 0 Then
    groupMonth.Value = [blue]Null[/blue]
    MsgBox "No records matched your criteria"
  End If
End Sub

VBSlammer
redinvader3walking.gif

"You just have to know which screws to turn." - Professor Bob
 
... toggle buttons that apply filters to a form ... dec 2005 filter ... the toggle gets stuck in the down position

- Toggle buttons have a value of True and False
- The value of the toggle button changes as the toggle button is "toggled" down and up with each mouse click or space bar if the toggle button has the focus.

The "gets stuck in the down position" may just mean that you have pushed the button down. Clicking on the toggle button again may move the toggle button back up.

You appear to want to apply filters -- perhaps display records for selected periods (yyyy + mmm).

Using the toggle button approach may work. For example, you select certain months by depressing various "toggles".

To "unstick" a toggle box, you can test the condition (record count > 0) and if the record count = 0, then reset the toggle box, Me.YourToggleBox = Me.YourToggleBox * -1, and then set the Locked value to no, Me.YourToggleBox.Locked = True (don't forget it reset the Locked value back to false later).

But perhaps another approach is to use either two unbound text boxes, or two unbound combo boxes to choose the start and end periods. Much easier to code, and probably easier for the end user.

Richard
 
hi again,

thanks for the above, firstly gonna keep with the toggle buttons for a while just to see if I can get it to work.
Starting with the basics - I don't think the group value is being set. With the wizard I set up a new group with 2 toggle buttons and tried this code:

Private Sub Frame127_AfterUpdate()
Select Case Frame127.Value
Case 1
MsgBox "choice 1"
Case 2
MsgBox "choice 2"
etc

nothing happens when clicking on the buttons.
I've also tried saving the option value to a particular field but nothing. Perhaps you could give it a quick go yourselfs, if it works for you I think I'll just use a combo box

thanks in advance
barry
 
Barry,
I can't see anything obviously wrong with your frame code. I tried it just now and it works. Here's the exact code I used:
Code:
Private Sub Frame0_AfterUpdate()
Select Case Me!Frame0.Value
    Case 1
        MsgBox "You clicked " & Me!Toggle3.Caption
    Case 2
        MsgBox "You clicked " & Me!Toggle4.Caption
    Case 3
        MsgBox "You clicked " & Me!Toggle5.Caption
End Select
End Sub
I also tried it without ".value" and without "Me!" and it worked that way, too. Sorry, I don't know what's hanging you up.

Ken S.
 
hi Eupher

thought I would try it in a blank database - and not suprisingly it works fine! Will work it out, thanks for the help

seeya
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top