Link to home
Create AccountLog in
Avatar of SheaJeff
SheaJeffFlag for United States of America

asked on

Toggle Button; why do I need to click twice to get it to do it's thing?

I have a toggle button for Approval that works so:

ToggleButton_Click()

If ToggleButton then
  - change button text to "Approved"
  - fill in username and date in 2 text fields
  -DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70 (to update the username and text fields immediately

Else
  - change button text to "" (blank)
  - set username and date to null (remove any values filled in above)
  - DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

End if
Exit sub

This all works fine, but it seems I have to click the button ONCE to "give it focus" or something, then when I click it a second time, it will perform correctly.

Why am I needing to click it twice? And how can I fix this?
Avatar of DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
Flag of United States of America image

Try the AfterUpdate even instead of the Click event.

mx
However ... this works for me:

Private Sub Toggle32_Click()
    If Me.Toggle32 = True Then
        MsgBox "TRUE"
    Else
        MsgBox "FALSE"
    End If
End Sub

mx
did you set the Triple State property of the toggle button to NO
RE:

"- change button text to "" (blank)

Seems odd you would not show something in the Caption when off ...?

mx
ASKER CERTIFIED SOLUTION
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
the Triple state property when set to yes, the toggle button cycles through 3 values
 -1,0,Null

when set to NO it will cycle through two values -1,0
And the 3rd state is the Grayed out version of the False condition, which in this case is "" (blank) ... giving the impression that you have to click twice to see anything.

So the question is ... is tri-state set to Yes ?

mx
Avatar of SheaJeff

ASKER

Button Triple state is set to No, and I tried adding the = True, and changing to AfterUpdate.  None of it worked.

I stepped through the process, and found that the problem may lie with the
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
as after I do this, the VBA goes to the AfterUpdate of the FORM, and does some update queries for other things.

I'm not sure but it seems like this "unselects" the button (yes, i have it enabled).  
The first click actually "selects" the button (highlighted like it's a tab stop- which is set to NO), then the second click actually performs the VBA.

Any other ideas?
SheaJeff,

try the codes i suggested at http:#a34467996
Try this:


ToggleButton_AfterUpdate()

If Me.ToggleButton = True then
  - change button text to "Approved"
  - fill in username and date in 2 text fields
   Me.Dirty = False ' save record

Else
  - change button text to "" (blank)
  - set username and date to null (remove any values filled in above)
    Me.Dirty = False ' save record

End if
Exit sub
The trick was to look at the current caption when the toggle button was clicked, instead of just saying toggle = true or false!
Isn't that what you were doing in the original post ?

If ToggleButton then
  - change button text to "Approved"  *** here ***

?
The important part was the .caption part:

If Me.ToggleButton.caption="" then