Toggle button

  • Thread starter samotek via AccessMonster.com
  • Start date
S

samotek via AccessMonster.com

I have two command buttons, CmdNew and CmdOld, where by clicking the first i
make the second visible and vice versa for example
Private Sub CmdNew_Click()
Me!CmdOld.Visible = True
End Sub
I want to use only one toggle button instead,with two captions"Old" and "New".

I have difficulties with making the buttons visible and invisible.Also.if i
click New, the caption Old must appear and stay until i have clicked it.If i
click Old, the caption Old must appear and stay until i click it.

How could i do that ?
 
M

MikeJohnB

One way to do what you want is to use the caption propert of the button as
follows:

Private Sub Cmd37_Click()
If Me.Cmd37.Caption = "New" Then
Me.Cmd37.Caption = "Old"
Else: Me.Cmd37.Caption = "New"
End If
End Sub

This will toggle the caption on one button from New to Old and back to New.
What else is the button supposed to do though?

~~~~~~~~~~~~~~~~~~~~

Another way is to do the job in the same way you have except make both
buttons exactly the same size and sit one on top of the other.

Your code
Private Sub CmdNew_Click()
Me!CmdOld.Visible = True
End Sub

Should also include

Private Sub CmdNew_Click()
Me!CmdOld.Visible = True
Me,CmdNew.Visible = False 'This line added
End Sub

And for CmdOld

Private Sub CmdNew_Click()
Me!CmdOld.Visible = False
Me,CmdNew.Visible = True
End Sub

You would have to set one visible and one not on the on open event of the form

Private Sub Form_Open(Cancel As Integer)
Me!CmdOld.Visible = False
Me,CmdNew.Visible = True 'Would set the open view "New" as default
End Sub

I would recommend the first option as being the most tidy way of doing the
job and it only requires one button
 

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