Change button caption on click...

H

Hitesh Joshi

I need small help..
I have cmdButton with caption like 'Hide form'
so when user clicks on the button it hides the subform and button
becomes sunken...
I want to change the caption to 'display form'.. and when he clicks on
'display form' the caption would become 'hide form' and form would
appear. I got form part hiding - diaplying just don't know how to
change the caption.

any hints or ideas?

Thank you,
hj
 
B

Brendan Reynolds

If cmdWhatever.Caption = "Hide form" Then
cmdWhatever.Caption = "display form"
Else
cmdWhatever.Caption = "Hide form"
End If

Where 'cmdWhatever' is the name of your command button.
 
H

Hitesh Joshi

This is what I have in code:

Private Sub cmdToggle_Click()
Me!Child26.Form.Visible = Not Me!Child26.Form.Visible
End Sub
 
F

fredg

This is what I have in code:

Private Sub cmdToggle_Click()
Me!Child26.Form.Visible = Not Me!Child26.Form.Visible
End Sub

If the button stays sunken, you do not have a command button but a
toggle button.

Private Sub cmdToggle_Click()
If Me!cmdToggle.Caption = "Display Form" Then
Me!Child26.Form.Visible = True
Me!cmdToggle.Caption = "Hide Form"
Else
Me!cmdToggle.Caption = "Display Form"
Me!Child26.Form.Visible = False
End If
 
J

John Vinson

I need small help..
I have cmdButton with caption like 'Hide form'
so when user clicks on the button it hides the subform and button
becomes sunken...
I want to change the caption to 'display form'.. and when he clicks on
'display form' the caption would become 'hide form' and form would
appear. I got form part hiding - diaplying just don't know how to
change the caption.

any hints or ideas?

Thank you,
hj

Try changing it to do both operations. A bit more code...

Private Sub cmdToggle_Click()
If Me!Child26.Visible Then
Me!Child26.Visible = False
Me!cmdToggle.Caption = "Hide Form"
Else
Me!Child26.Visible = True
Me!cmdToggle.Caption = "Display Form"
End If
End Sub

I'm hiding or showing the Subform Control itself rather than the form
within that control - you can do either, it just looks wierd to me to
have a subform with blank white.

John W. Vinson[MVP]
 

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