Check Box / Enter date (1 Viewer)

LarneTim

New member
Local time
Today, 19:49
Joined
Jul 18, 2009
Messages
4
I am sure this must be easy, I have a field called "Reception Date" on selection of a check box I need an auto date input into the Reception Date"

Thanks for your help.
 

RuralGuy

AWF VIP
Local time
Today, 12:49
Joined
Jul 2, 2005
Messages
13,826
Do you want the current DateTime value stored in the field?
Me.ControlName = Now() should do it
 

LarneTim

New member
Local time
Today, 19:49
Joined
Jul 18, 2009
Messages
4
Do you want the current DateTime value stored in the field?
Me.ControlName = Now() should do it

Some more help please, because I basically don't know what I am doing.

I have a Check box called "Cocher26" on selection of this box I would like an auto date input into to a text box called RECEPTION_DATE.

Be gentle, do I select the RECEPTION_DATE right mouse click and select the build event for this text box. Can someone explain the steps after this, or just supply a dummy guide for the steps to get this to work.
 

RuralGuy

AWF VIP
Local time
Today, 12:49
Joined
Jul 2, 2005
Messages
13,826
You need to get to the Event tab of the Properties sheet for the Cocher26 CheckBox. You do that with a right click on the control in design view and select Properties. The is a Click event on the Event tab with a "..." button to the right side. Push the "..." button and select code. Then in between the stub code put:
Me.RECEPTION_DATE = Now()
You will need to decide what you want to happen when the user "UnChecks" the box.
 

missinglinq

AWF VIP
Local time
Today, 14:49
Joined
Jun 20, 2003
Messages
6,423
In form Design View, select View - Code then paste this into the code window:

Code:
Private Sub Cocher26_Click()
 If me.Cocher26=-1 then
  Me.Reception_Date = Date
 Else
  Me.Reception_Date = Null
 End If
End Sub
The Else clause is needed in case the user mistakenly ticks the checkbox then changes his/her mind.

You can replace Date with Now as Allan suggested, if you need date and time. For just date, especially if you're going to be comparing the reception date with the current date, keep the Date.
 

LarneTim

New member
Local time
Today, 19:49
Joined
Jul 18, 2009
Messages
4
Guys thank you so much for your help, saved me hours of messing around. Worth several beers. Thanks again.
 

KathyJean

New member
Local time
Today, 11:49
Joined
Apr 4, 2019
Messages
8
I have something similar to this. I want the EndDate to add one month on the EndDate date if the MTM is checked. So if MTM is True, and it's November 29, 2019, I want it to add a month when it's November 30, 2019. I tried this:
=((([tbl_ContractInformation].[MTM])=IIf([MTM]=True,[EndDate]=[EndDate],+"m")))

I know I'm missing the actual date, but I can't figure this out. Hope this is enough information.

Thanks.
 

mike60smart

Registered User.
Local time
Today, 18:49
Joined
Aug 6, 2017
Messages
1,899
Hi Kathy

Try this

If me.MTM=-1 then
DateAdd(“m”,1,[EndDate])
Else
[EndDate]
End If
 

KathyJean

New member
Local time
Today, 11:49
Joined
Apr 4, 2019
Messages
8
Thanks Mike60smart - I will try this over the weekend and get back with you. :)
Kathy
 

KathyJean

New member
Local time
Today, 11:49
Joined
Apr 4, 2019
Messages
8
mike60smart

I tried what you have but after I type the second line and return, I get an error "Compile error: Expected: =
Am I having a "user" problem? :)

Thanks.
 

mike60smart

Registered User.
Local time
Today, 18:49
Joined
Aug 6, 2017
Messages
1,899
Try just this

If me.MTM=-1 then
DateAdd(“m”,1,[EndDate])
End If
 

missinglinq

AWF VIP
Local time
Today, 14:49
Joined
Jun 20, 2003
Messages
6,423
I don't quite get this:
...So if MTM is True, and it's November 29, 2019, I want it to add a month when it's November 30, 2019...

You want to add a month to the day after the day you're checking the MTM Checkbox? Or was tat a mistype? The error you're getting is because Mike's was apparently having a bad day...the code should have been

Code:
[B]If Me.MTM=-1 then
  [COLOR="Red"]Me.EndDate =[/COLOR] DateAdd("m",1, Me.EndDate)
Else
  [COLOR="red"]Me.EndDate =[/COLOR] Me.EndDate 
End If[/B]

Note that since EndDate has no space in the name, the Brackets aren't needed, in this application.

Having said that...we come to the question of where to place the code!

Normally this would go in the MTM_AfterUpdate event...but what if the EndDate doesn't have a date enterd yet? You cannot depend on the user entering data in the sequence you expect them to. So the next question is how is EndDate populated? By the user physically entering a date? Does it have a Default Date that populates it when a new Record is started? How?

Linq ;0)>
 

KathyJean

New member
Local time
Today, 11:49
Joined
Apr 4, 2019
Messages
8
Linq,
Thanks for the info. I manually put in the end date when I open a new record. The Vendor will either be MTM or Auto Renew.

If I have a new vendor today, then on December 5, I want it to be changed to January 5. Will it also update the year?

Going to go try that now.

Thanks,
Kathy
 

Users who are viewing this thread

Top Bottom