Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem with adding days to a date 2

Status
Not open for further replies.

davyre

Programmer
Oct 3, 2012
197
AU
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
 
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 :(
 
What about this ?
insertDateQry = "UPDATE TblCustOrder SET CustomerUDD=#" & Format(defaultDate, "yyyy-mm-dd") & "#, ASAP='" & ASAP & "' WHERE CustOrderID=" & CustOrderID

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
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
 
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!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top