View Full Version : Command Button


jax
03-18-2002, 03:48 AM
I have a command button on a form, it opens a calendar from which the user choses a date. I want the user to be able to click the same command button to close the calendar. Is it possible or do I have to create another close calender button. If it is possible how is the code written?

Thanks for any help

Rich
03-18-2002, 03:53 AM
If IsLoaded("MyForm") Then
DoCmd.Close etc.

jax
03-18-2002, 04:03 AM
Thanks Rich but I didnt quite understand your reply, where does the if statement you suggest go - on the OnClick of the command button or on the calender?

Sorry for my ignorance!

Rich
03-18-2002, 04:09 AM
I took it to be that you wanted to close the calendar from the main form using the same button that opens the calendar, however if you have a button on the calendar which sets the date to your form, just add DoCmd.Close as another line on the code for your calendar button.
HTH

jax
03-18-2002, 04:46 AM
Rich
The command button is on a form, your right I want the button to open the calendar on the first click and close it on the second. I have the first bit working with the code:

Private Sub Button_Click()
Calendar.Visible = True
Calendar.SetFocus
End Sub

I am not sure how to fit your IF statement into the above code.

Thanks for your time.
Jax

jax
03-18-2002, 06:05 AM
Can anyone help me with my command button problem?

Fizzio
03-18-2002, 07:40 AM
I see you are hiding rather than closing the form, or is the calendar on the same form?

If it is on the same form then try this

Private Sub Button_Click()

If Me.Calendar.Visible = True then
Me.Calendar.Visible = False
Else: Me.Calendar.Visible = True
Me.Calendar.SetFocus
End If

End Sub

jax
03-18-2002, 07:48 AM
Thank you Fizzio it works brilliantly

You dont know how many grey hairs I have trying to work that one out.

Thanks again

Jax