Normal Topic Date function... (Read 480 times)
Cliff
Full Member
***
Offline



Posts: 126
Location: New Hampshire
Joined: May 5th, 2006
Date function...
Jun 5th, 2007 at 6:07pm
Print Post Print Post  
I am trying to pre-populate an application by populating a particular element in the form with the current (today's) date.

I can accomplish that easy enough, however, my challenge is to have the date pre-populate ONLY when we open the form in "Add-Data" mode. 

This date field should show (needs to) whatever date has been entered and saved from previous work when opening the form in "Search/Update" mode.

My attemps fill this element field regardless of what mode we open the form in with today's date.

I do appreciate any and all assistance and I am dutifully trying to code these things on my own before dunning you all here...

Again...

Thanks...

Cliff
  
Back to top
 
IP Logged
 
Ben
Lantica Support
*****
Offline



Posts: 218
Joined: Apr 7th, 2005
Re: Date function...
Reply #1 - Jun 5th, 2007 at 6:12pm
Print Post Print Post  
You can use @IsNew to check if you are on a new record.

Code
Select All
If @IsNew Then
{
     DateField = @Date
} 

  
Back to top
IP Logged
 
Cliff
Full Member
***
Offline



Posts: 126
Location: New Hampshire
Joined: May 5th, 2006
Re: Date function...
Reply #2 - Jun 5th, 2007 at 6:34pm
Print Post Print Post  
Thank you kindly...!
Much appreciated...

Cliff
  
Back to top
 
IP Logged
 
Carl Underwood
Senior Member
Members
*****
Offline



Posts: 1351
Location: New Hampshire
Joined: Mar 11th, 2003
Re: Date function...
Reply #3 - Jun 5th, 2007 at 11:47pm
Print Post Print Post  
Cliff,

Be careful not to simply place that code into the On Form Entry event. If you do this you can end up with many forms that are empty except for the date field.

A good place for such code is in the On Form Change event. That way, the date only fills in once you begin entering data in other fields (a good sign that the record will contain some useful info, rather than blank fields. Wink)

Another option you may (or may not, depending on your situation) want to include, is the ability to modify the date when adding new records. The following code, placed in On Form Change, will automatically fill in the date, but also allow you to change it if needed. Without using "@IsBlank(DateField)" as below, you will not be able to manually adjust the date while adding a new record.

Code
Select All
If @IsNew and @IsBlank(DateField)
{
	DateField = @Date
} 

  


Carl Underwood
CDU Computer Consulting LLC
Epsom, New Hampshire
Back to top
IP Logged