Writing to a date field in Access

Results 1 to 2 of 2

Thread: Writing to a date field in Access

  1. #1
    Big Mac Guest

    Default Writing to a date field in Access

    Hi,<BR><BR>...<BR>dim sLDate<BR>sLDate = Month(Date) & "-" & Day(Date) & "-" & Year(Date)<BR>...<BR>objRSAdd.AddNew<BR>objRSAdd(" DATEORDERED")=sLDate<BR>objRSAdd.Update<BR>...<BR> <BR>In my Access DB, my DATEORDERED field format can be any format format and it would be written in as defined. I&#039m just wondering if this is the right way of doing it. ie Is it better code to define sLDate in the format that Access is defined?<BR><BR>Thanks.

  2. #2
    Neil Popham Guest

    Default RE: Writing to a date field in Access

    I am a little concerned with your method.<BR><BR>For one thing, you are taking a date and converting it to a string then entering it into a date field.<BR><BR>Also, the method surely does not ensure that the date is being processed in the correct form ie: mm-dd-yy. Just because you are creating the string in that form, doesn&#039t mean that access will be expecting it thus, it may be expecting dd-mm-yy. I&#039m a little cloudy on this one, and I may be barking up the wrong tree (or just barking), as I am from UK and have inherant problems with the mm-dd-yy / dd-mm-yy thing.<BR><BR>With this in mind, my suggested line would be:<BR><BR>&#062; objRSAdd.AddNew<BR>&#062; objRSAdd("DATEORDERED")=FormatDateTime(Date(), vbLongDate)<BR>&#062; objRSAdd.Update<BR><BR>this ensures that we all know what date we are talking about, because it is the format &#03908 December 1999&#039.<BR><BR>i am keen to hear any further suggestions though...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts