Enable Button based on Date box Values

Paul Cooke

Registered User.
Local time
Today, 16:59
Joined
Oct 12, 2001
Messages
288
Hi Guys

I am getting confused trying to code a button after dates have been entered in two boxes - Start Date and End Date

On opening the form the cmd button (View Reports) is disabled. The user enters dates in the Start and End date boxes, once this is done the cmd button enables.

However if they decide to clear the dates (using another cmd button 'clear Dates') then I need the View Reports button to go back to being disabled.

I have tried the following on lost focus, on change ect but noting seems to work!

Code:
'Enables Cmd View Report if dates have been entered

If Me.txtDateStart.Value = "" And Me.txtDateEnd.Value = "" Then

    Me.cmdViewReport.Enabled = False

Else

    Me.cmdViewReport.Enabled = True

End If

any advice greatfully recieved - many thanks
 
Hi, Paul,

Try this change to your code:
Code:
If Not IsNull(Me.txtDateStart.Value) And Not IsNull(Me.txtDateEnd.Value) Then

    Me.cmdViewReport.Enabled = True

Else

    Me.cmdViewReport.Enabled = False

End If
 
I'd try your code in the afterUpdate events of both txtDateStart and txtDateEnd

Also, for the Reset/ClearDates cmd code I'd suggest adding

Me.cmdViewReport.Enabled = False and perhaps
Me.cmdViewReport.Visible = False

Just my thoughts..
 
Hi..

You can also use this as an alternative way.

Me.cmdViewReport.Enabled = Not (IsNull(Me.txtDateStart.Value) Or IsNull(Me.txtDateEnd.Value))
 
Thanks for the replies guys ! I had a eureka moment just before reading this and worked out it would be better to use the 'Clear Dates' cmd to disable the other cmd button - thanks Jdraw on the same thought patterns there !!

Byron - thanks for the reply will email you soon hopefully this week !

Taruz - thanks for the alternate option !
 

Users who are viewing this thread

Back
Top Bottom