Hi All
This is my first attempt at any code but cannot get it to work. Please could someone help me correct the following code including the date formatting:
Public Function DateCode() As String
'1)If chrCoDivision = TS, then DateCode = Format([dtmDlyDate]+[dblMaxShelfLife]) as ”dd mmm”)
'2)If chrCoDivision = TM and dtmFinalDepotDly is null,
'then DateCode = Format(([dtmDlyDate]+[dblMaxShelfLife])- 9 Weeks) as ”Wk 00 ddd”)
'3)If chrCoDivision = TM, FinalDepotDly is not null
'and DateDiff([dtmDlyDate],[dtmFinalDepotDly]) > ([dblMaxShelfLife]-[dblMinShelfLife])
'then DateCode = Format(([dtmDlyDate]+[dblMaxShelfLife])- 9 Weeks) as ”Wk 00 ddd”)
'4)If chrCoDivision = TM, FinalDepotDly is not null
'and DateDiff(d,[dtmDlyDate],[dtmFinalDepotDly]) <= ([dblMaxShelfLife]-[dblMinShelfLife])
'then DateCode = Format(([dtmFinalDepotDly]+[dblMinShelfLife])- 9 Weeks) as ”Wk 00 ddd”).
Dim dtmDlyDate As Date
Dim chrCoDivision As String
Dim dtmFinalDepotDly As Date
Dim dblMaxShelfLife As Double
Dim dblMinShelfLife As Double
If chrCoDivision = "TS" Then
DateCode = Format([dtmDlyDate] + [dblMaxShelfLife], "dd mmm", vbSunday)
ElseIf chrCoDivision = "TM" And dtmFinalDepotDly = "" Then
DateCode = CStr("Wk " & _
(Format(DatePart("ww", DateAdd("ww", -9, ([dtmDlyDate] + [dblMaxShelfLife])), 1), "00")) _
& " " & (Format([dtmDlyDate] + [dblMaxShelfLife], "ddd")))
ElseIf chrCoDivision = "TM" And dtmFinalDepotDly <> "" Then
If DateDiff("d", [dtmDlyDate], [dtmFinalDepotDly]) > ([dblMaxShelfLife] - [dblMinShelfLife]) Then
DateCode = CStr("Wk " & _
(Format(DatePart("ww", DateAdd("ww", -9, ([dtmDlyDate] + [dblMaxShelfLife])), 1), "00")) _
& " " & (Format([dtmDlyDate] + [dblMaxShelfLife], "ddd")))
ElseIf DateDiff("d", [dtmDlyDate], [dtmFinalDepotDly]) <= ([dblMaxShelfLife] - [dblMinShelfLife]) Then
DateCode = CStr("Wk " & _
(Format(DatePart("ww", DateAdd("ww", -9, ([dtmDlyDate] + [dblMaxShelfLife])), 1), "00")) _
& " " & (Format([dtmFinalDepotDly] + [dblMinShelfLife], "ddd")))
End If
Else
DateCode = ""
End If
End Function
I have written what I would like to achieve at the top of the function to help people understand what I am tryin g to do.
Thanks in advance
Regards
Antony
This is my first attempt at any code but cannot get it to work. Please could someone help me correct the following code including the date formatting:
Public Function DateCode() As String
'1)If chrCoDivision = TS, then DateCode = Format([dtmDlyDate]+[dblMaxShelfLife]) as ”dd mmm”)
'2)If chrCoDivision = TM and dtmFinalDepotDly is null,
'then DateCode = Format(([dtmDlyDate]+[dblMaxShelfLife])- 9 Weeks) as ”Wk 00 ddd”)
'3)If chrCoDivision = TM, FinalDepotDly is not null
'and DateDiff([dtmDlyDate],[dtmFinalDepotDly]) > ([dblMaxShelfLife]-[dblMinShelfLife])
'then DateCode = Format(([dtmDlyDate]+[dblMaxShelfLife])- 9 Weeks) as ”Wk 00 ddd”)
'4)If chrCoDivision = TM, FinalDepotDly is not null
'and DateDiff(d,[dtmDlyDate],[dtmFinalDepotDly]) <= ([dblMaxShelfLife]-[dblMinShelfLife])
'then DateCode = Format(([dtmFinalDepotDly]+[dblMinShelfLife])- 9 Weeks) as ”Wk 00 ddd”).
Dim dtmDlyDate As Date
Dim chrCoDivision As String
Dim dtmFinalDepotDly As Date
Dim dblMaxShelfLife As Double
Dim dblMinShelfLife As Double
If chrCoDivision = "TS" Then
DateCode = Format([dtmDlyDate] + [dblMaxShelfLife], "dd mmm", vbSunday)
ElseIf chrCoDivision = "TM" And dtmFinalDepotDly = "" Then
DateCode = CStr("Wk " & _
(Format(DatePart("ww", DateAdd("ww", -9, ([dtmDlyDate] + [dblMaxShelfLife])), 1), "00")) _
& " " & (Format([dtmDlyDate] + [dblMaxShelfLife], "ddd")))
ElseIf chrCoDivision = "TM" And dtmFinalDepotDly <> "" Then
If DateDiff("d", [dtmDlyDate], [dtmFinalDepotDly]) > ([dblMaxShelfLife] - [dblMinShelfLife]) Then
DateCode = CStr("Wk " & _
(Format(DatePart("ww", DateAdd("ww", -9, ([dtmDlyDate] + [dblMaxShelfLife])), 1), "00")) _
& " " & (Format([dtmDlyDate] + [dblMaxShelfLife], "ddd")))
ElseIf DateDiff("d", [dtmDlyDate], [dtmFinalDepotDly]) <= ([dblMaxShelfLife] - [dblMinShelfLife]) Then
DateCode = CStr("Wk " & _
(Format(DatePart("ww", DateAdd("ww", -9, ([dtmDlyDate] + [dblMaxShelfLife])), 1), "00")) _
& " " & (Format([dtmFinalDepotDly] + [dblMinShelfLife], "ddd")))
End If
Else
DateCode = ""
End If
End Function
I have written what I would like to achieve at the top of the function to help people understand what I am tryin g to do.
Thanks in advance
Regards
Antony