DateAdd as a string

MattioMatt

Registered User.
Local time
Today, 15:19
Joined
Apr 25, 2017
Messages
99
Hello,

Is it possible to output the results of the DateAdd function as a string in a query?

I'm currently using the DateAdd function to work out a date 6 months (Field Name: DueDate) from a date specified from another field (Field Name: ValidatedDate). I'm then wanting this to output a status that will be for example "Overdue [26/07/2018]". The date part being what the DataAdd result is, I'm hoping that makes sense?

I'm having trouble outputting the result in a string - any help much appreciated.
 
Why do this in a query? Why not build a report and expression in textbox can concatenate text with date field.
 
If DueDate is always 6 months after ValidatedDate, then the field isn't needed as it can be calculated as required

For your string, you can use:
Code:
"Overdue & [" & DateAdd("m",6,ValidatedDate) & "]"

e.g. "Overdue & [" & DateAdd("m",6,#7/26/2018#) & "]" gives
- Overdue & [01/26/2019] in mm/dd/yyyy format
- Overdue & [26/01/2019] in dd/mm/yyyy format
 
I think Ridders answer is the better one but this addresses the exact question:



Code:
Private Sub Command0_Click()
Dim datDueDate As Date
Dim datPlusSix As Date
Dim strMessage As String

    datDueDate = #12/5/2018#                    'Use your date field here
    datPlusSix = DateAdd("m", 6, datDueDate)
    strMessage = "Overdue " & Format(datPlusSix, "dd/mm/yyyy")
    
    MsgBox strMessage
End Sub
 

Users who are viewing this thread

Back
Top Bottom