[AccessD] New thrd: dates

Stuart McLachlan stuart at lexacorp.com.pg
Thu Aug 21 16:50:08 CDT 2014


OK, here goes as asked for (an Access FE/BE):

Answers in line.

On 21 Aug 2014 at 15:46, Bill Benson wrote:

> I am really sorry I asked this one now! My question "what is meant by
> a GUI date just needed a yes or no to my illustration, to wit, " Is
> this a bound textbox reading a date from the back end?"; [or if not
> that, something else - and if so, what?].
> 

Yes.   It's the formatted date as displayed in a control on a form or report.

> Jim further said the effect would depend on
> <<1) the format the data is put into by the BE 
> I already posted:
> <<my backend had Aug 4th 2014 stored as 08/04/2014

No, your date is NOT stored iin an Access BE as 08.04/02014.  It is stored as
the number 41855.0   which is the number of days since 30 Dec 1899.

> I had written (*emphasis* added):
> > When *I take that value* to enter it into the database (remember
> > backend is US) would I write
> >
> > Sql = "Insert into myTable (name, address, effective_dt) values ('"
> > & txtname & "','" & txtaddress & "', #" & txteffectivedate & "#)"
> 
> > Or
> > Sql = "Insert into myTable (name, address, effective_dt) values ('"
> > & txtname & "','" & txtaddress & "', #" & cdate(txteffectivedate) &
> > "#)"

It doesn't matter whether the BE is US or UK, the date is stored as the same number.  

The problem is that the SQL engine in the Access FE requires a date surrounded by "#"s to 
be in a specific format, which may not be the format in which txtEffectiveDate is being 
displayed. (In a European FE, the txtEffectiveDate could be 08/04/2014, 04/08/2014,"04 Aug 
2014","Aug 4 2014" , "Auot 4 2014", or many other language specific formats.)       

There are two common solutions:

 Sql = "Insert into myTable (name, address, effective_dt) values ('"
 & txtname & "','" & txtaddress & _
"', #" & format(txteffectivedate,"mm/dd/yyyy") & "#)"

or

 Sql = "Insert into myTable (name, address, effective_dt) values ('"
 & txtname & "','" & txtaddress & _
"',Datevalue('" & txteffectivedate & "'))"

FWIW, I always use the second version and have never had a problem with it.




More information about the AccessD mailing list