473,379 Members | 1,423 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

Set field to current date if empty

I want to put some code behind a OnClick event, but I am coming up short.

I have a field on my form called [emailsent]. When a user clicks the button to print a report, I also want it to check if this field has anything in it, IF not, I want current date in it, otherwise, if it already has a date, I want that date to remain as is.

Could someone help me?

Thanks
Oct 22 '08 #1
6 9926
GazMathias
228 Expert 128KB
Expand|Select|Wrap|Line Numbers
  1. If isNull(Me.TextBoxName.Value) Or Me.TextBoxName.Value = "" Then
  2.   Me.TextBoxName.Value = Date
  3. End If
  4.  
  5. ... Code to run report.
In future, could you also post the code that is failing you? That way we can just point out what is wrong instead of writing code for you, and you'll feel a sense of achievement for the code you did get right ;)

Gaz
Oct 22 '08 #2
Expand|Select|Wrap|Line Numbers
  1. If isNull(Me.TextBoxName.Value) Or Me.TextBoxName.Value = "" Then
  2.   Me.TextBoxName.Value = Date
  3. End If
  4.  
  5. ... Code to run report.
In future, could you also post the code that is failing you? That way we can just point out what is wrong instead of writing code for you, and you'll feel a sense of achievement for the code you did get right ;)

Gaz
Thanks so much and yes in the future I will submit my code.
Oct 22 '08 #3
missinglinq
3,532 Expert 2GB
Also, be aware if you're running a report based on the current record, and the record is new or is an existing record that you've edited (like updating the date field) you need to explicitly save the record before running the report, using something like

If Me.Dirty Then Me.Dirty = False

Linq ;0)>
Oct 22 '08 #4
NeoPa
32,556 Expert Mod 16PB
@Gaz
Empty controls should always return Null rather than empty strings. IE. You should always get away with :
Expand|Select|Wrap|Line Numbers
  1. If IsNull(Me.TextBoxName) Then
PS. .Value is also the default property so is not generally required. It still works perfectly, but tends to detract from, rather than enhance the readbility.

PPS. I hope you don't feel you're being criticised. I can actually see how much help you're providing so I'm just throwing out some tips.

A very warm welcome to Bytes!
Oct 24 '08 #5
GazMathias
228 Expert 128KB
@Gaz
Empty controls should always return Null rather than empty strings. IE. You should always get away with :
Expand|Select|Wrap|Line Numbers
  1. If IsNull(Me.TextBoxName) Then
No probs mate, I always used to do that, but I have had instances in applications where errors have been thrown out and I found the only way around was to check for a zero length string, I guess because most of the data I work with comes from Sage Line 50 via ODBC. I do that in ASP too, thinking about it (again with the Sage stuff!). A habit hard to break, I would say.
Oct 24 '08 #6
NeoPa
32,556 Expert Mod 16PB
That may well make sense Gaz (I play with one ODBC Driver - two if you include MS SQL Server - but its foibles are specific to that particular driver).

Anyway, I see you are now a full member. Congratulations :)

PS. Do I gather from your terminology you're another Brit?
Oct 24 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Michael Haas | last post by:
Need some hwlp with comparing a date field retrieved from an access date base to the current date. Basically I'm looking to create and if statement like: If strArticleDate < = Current Date then...
7
by: James P. | last post by:
Hello there, In my asp.net page using VB, I have a date text field in mm/dd/yyyy format. When a date is entered, I'd like to validate it to make sure the date is greater than or equal to the...
4
by: rinmanb70 | last post by:
Is there a way to make a field on a report be visible or not depending one the current date?
2
by: rpboll | last post by:
Is there a function that stamps the FISCAL Date (Starting from October)? I am trying to generate a Fiscal Date and an AutoNumber for a key field. Thanks for any suggestions. RBollinger
1
by: Killer42 | last post by:
Hi all. I have a question from a colleague. He is creating a form in Word2003, which has a date field on it. He wants to set the default value to the current date, but allow the user to overwrite...
2
by: Twinkle | last post by:
Can anyone please help me with the following. I have an empty Varchar column for one table. I need to convert the datatype to date now. But i need the field to be empty. How can this be done. ...
4
by: mcca0081 | last post by:
hi - i'm trying to delete one of the duplicate records based on the most current date. here's the code for my access 2000 db. any help would be appreciated!!! - thank you kindly Sub...
7
by: sharmilah | last post by:
Hi all It's me again. I now want to specify the current date in the format '26/06/2007' ie date/month/year as the default value in my mysql database. Which implies that by default the value of my...
3
by: jomats | last post by:
I am a newbie trying to learn Access from several books. I'm sure this is an easy one to answer..for someone, not me. Is it possible to insert a checkbox on a form which, when checked, inserts the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.