Toggle Button (1 Viewer)

TobyMace

Registered User.
Local time
Today, 17:57
Joined
Apr 13, 2018
Messages
65
Hi All,


I have a toggle button that when clicked will make a sub report appear and when clicked again would make it disappear again.
I have tried to do this by assigning a macro to the OnClick to SetProperty visible of Courses_R to True.
I then assumed that clicking the toggle button again would revert that? (To assume is to make an ass out of u and me. I really have!)
Please help!
Or if any has an easier way to do this without a toggle button then I'd be most grateful.
Thanks in advance!
 

isladogs

MVP / VIP
Local time
Today, 17:57
Joined
Jan 14, 2017
Messages
18,216
Never tried with a toggle button. It may be that you just need to move the focus from the report to something else first so it can be hidden.

Or use a standard command button with caption Show Report.
When you click the button, add code to open the report and change the caption to Hide
Report
Now use if ... Else. End if code with the above in the If section and the reverse code in the Else section.
 

TobyMace

Registered User.
Local time
Today, 17:57
Joined
Apr 13, 2018
Messages
65
Private Sub ButtonName_Click()

If ButtonName.Value = True Then

Me.Control.Visible = True
Me.Control.Height = 2.3
Me.Control.Width = 19.7
Me.Detail.Height = 2.5

Else:

Me.Control.Visible = False
Me.Control.Height = 1
Me.Control.Width = 1
Me.Detail.Height = 0.75

End If

End Sub


Is the solution. Doh! Seems simple now I know!
Hope this helps someone else out there!
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 12:57
Joined
Feb 19, 2002
Messages
43,266
Try to be consistant in how you reference controls.

Me.ControlName is the preferred method. the .Value property is the default for most control types and so is normally omitted to shorten the code.

"Me." defines the library where the object is defined and is only used within a form or report's class module when referring to a control on the form where the code is running. "Me." gives you intellisense and compile time error checking. In newer versions of Access "Me!" now gives you intellisense ( it doesn't in older versions) but it does not always give you compile time errors which makes it a little more dangerous to use since if you misspell something, you won't get an immediate error. You won't see the error until you run the code and get to the line with the error.
 

Users who are viewing this thread

Top Bottom