Disable a checkbox after a certain date (1 Viewer)

Joosje

New member
Local time
Today, 03:51
Joined
Mar 18, 2010
Messages
7
Hi,

I have a userform with which clients can order stuff. There is a discount that applies for people who order before the deadline (04/13/2010). The discount is named Early Bird Discount and there is a check box that users can click to receive the discount. But I want the check box to get hidden or disabled after this date. How do I do this in VBA coding ?

If any body knows please hellppppp ! Thank you !
 

vbaInet

AWF VIP
Local time
Today, 11:51
Joined
Jan 22, 2010
Messages
26,374
Welcome to AWF :)

Is this for a subform or a form?
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 03:51
Joined
Aug 30, 2003
Messages
36,123
Test for the current date being after the deadline (If/Then block, Date() function), and disable the checkbox appropriately:

Me.CheckboxName.Enabled = False
 

Joosje

New member
Local time
Today, 03:51
Joined
Mar 18, 2010
Messages
7
Thank you!!
I tried this code and it's working.

If The_Date.Value > #3/17/2010# Then
Early_Bird_Discount.Value = False And Early_Bird_Discount.Enabled = False
MsgBox "Sorry, this promotion has expired. "
End If

One thing though; you have to click twice on "OK" when the msgbox appears to continue filling out the form. If you have any feedback on it please shoot. TNX!
 

Khalid_Afridi

Registered User.
Local time
Today, 13:51
Joined
Jan 25, 2009
Messages
491
Perfect!

in addition to Mr. Paul
Code:
Private Sub Form_Current()

If Date > #4/13/2010# Then
    Me.Check0.Enabled = False
End If

End Sub

Khalid
 

Galaxiom

Super Moderator
Staff member
Local time
Today, 20:51
Joined
Jan 20, 2009
Messages
12,851
BTW When addressing an object with multiple commands this format is faster and easier to enter and read.
Code:
With Me!Early_Bird_Discount
     .Value = False
     .Enabled = False
End With

You will also want to make the test against a date stored somewhere rather than a date hard coded in the VBA.
 

vbaInet

AWF VIP
Local time
Today, 11:51
Joined
Jan 22, 2010
Messages
26,374
Just as a follow-up to what GalaxiomAtHome mentioned the With is very useful especially when you want to reference at least 3 or more methods or properties. It's not really advisable for less.
 

Galaxiom

Super Moderator
Staff member
Local time
Today, 20:51
Joined
Jan 20, 2009
Messages
12,851
Just as a follow-up to what GalaxiomAtHome mentioned the With is very useful especially when you want to reference at least 3 or more methods or properties. It's not really advisable for less.

I think the point where we use them is a personal preference.

As time goes by I have tended to use it right down to just two properties. It neatly groups the code and I expect it is slightly faster to execute. It reduces the task of editing if an object name is changed.

However I will generally fully address small numbers of properties rather than nest a With as some developers believe it makes code harder to read.
 

vbaInet

AWF VIP
Local time
Today, 11:51
Joined
Jan 22, 2010
Messages
26,374
I think the point where we use them is a personal preference.

As time goes by I have tended to use it right down to just two properties. It neatly groups the code and I expect it is slightly faster to execute. It reduces the task of editing if an object name is changed.

However I will generally fully address small numbers of properties rather than nest a With as some developers believe it makes code harder to read.
Correct. There's the aspect of personal preference. I once saw an article that compared (using milliseconds) the With statement to fully qualifying the object and it showed the results in a bar chart. The chart wasn't in favour of short uses of the With statement. I can't find the link in my many favourites but I will post it if I do.
 

Galaxiom

Super Moderator
Staff member
Local time
Today, 20:51
Joined
Jan 20, 2009
Messages
12,851
Good to know about the speed penalty not matching my expectation. I will factor that into my decisions now.

One thing I like about using With down to small groupings is the ease when adding another property edit later. Spelling out every line can start to look excessive as the number of lines increases.

However avoiding the work to change to the With grouping format sometimes means maybe five full length lines end up in the code.
 

vbaInet

AWF VIP
Local time
Today, 11:51
Joined
Jan 22, 2010
Messages
26,374
It's great I use them alot too :D . It just looks really neat and alot easier to read like you mentioned. Very helpful when you're referencing properties of objects down a couple of levels. They can be a hassle, phew!
 

Users who are viewing this thread

Top Bottom