INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

problem with adding days to a date

problem with adding days to a date

(OP)
Hi,
I have a field named OrderDate, which the user inputs Short Date (dd/mm/yyyy) from a textbox (DatePicker enabled).
Now in some condition, another field named CustomerUDD is empty (not specified/intended to be left blank). Now I am creating a button to fill the blank CustomerUDD to add 30 days from OrderDate (only for the blank CustomerUDD).
heres my code:

CODE

Dim defaultDate As Date
Dim CUDD As Date
Dim CustOrderID As Long
Dim insertDateQry As String
Dim ASAP As String

ASAP = "(ASAP)"
CustOrderID = Me.CustOrderIDBox.Value
defaultDate = DateAdd("d", 30, Me.OrderDate.Value)
insertDateQry = "UPDATE TblCustOrder SET CustomerUDD=#" & defaultDate & "#, ASAP='" & ASAP & "' WHERE CustOrderID=" & CustOrderID

If IsNull(DLookup("CustomerUDD", "TblCustOrder", "CustOrderID=" & CustOrderID)) Then
    DoCmd.SetWarnings False
    DoCmd.RunSQL insertDateQry
    DoCmd.SetWarnings True
    
    MsgBox ("Default date has been inserted (30 days from Order Date).")
End If 

now the problem is, while the OrderDate are in a correct format(dd/mm/yyyy), the CustomerUDD sometimes messed up(changed the format to mm/dd/yyyy) which causes problem to the report. How can I solve this so the CustomerUDD does not use mm/dd/yyyy format, but instead using dd/mm/yyyy? I said sometimes, because sometimes it is in correct format, sometimes not. Why such inconsistency? Thanks

RE: problem with adding days to a date

(OP)
thanks Duane,

I tried to use defaultDate=CVDate([Me.OrderDate.Value]+30) but still not working.
Btw the format I used (dd/mm/yyyy) was proper (in the textbox OrderDate, I choose the "Short Date" format in the property sheet). But I guess Access treated the input differently. Helppp :(

RE: problem with adding days to a date

davyre,
Clearly the link I provided suggests using "#" & Format(Me.StartDate, "mm\/dd\/yyyy") & "#". I'm not sure why you ignored the advice and continued down a path that hadn't worked before.

Duane
Hook'D on Access
MS Access MVP

RE: problem with adding days to a date

(OP)
thanks PH, I think it works well.

to Duane, I thought you suggested me to use the CVDate function as it is clearly used for calculated date fields
"The solution is to explicitly typecast all calculated date fields, e.g.: DueDate: CVDate([InvoiceDate] + 30)"

thanks guys!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close