Good morning and Happy New Year,
I am a novice when it comes to VBA programming, but I feel pretty confident in normal Access functionality. I'm stuck when it comes to conditional formatting. I've developed a program that prints a report of how long a work order has been open. However, I would like to make WO's that have been open for less than 1 day to print in 1 color and those that have been open more than 1 day, but less than 3 days to print in another color. There are 2 catches to this:
1) The "# of days open" field displays the calculation as a text string
2) There is another field called MINOR_MAJOR that I want to play a role in this report.
If the WO is MINOR and is also less than 1 day, it should be bolded. If this WO is MAJOR and between 1 and 3 days, it should be bolded (another color). Anything outside this metric can be normal text. Here's the code I've been using to get the calculation to show as days, hours, minutes, and seconds. Can I build these conditions into this code? Thanks for any help!!
Public Function ElapsedTimeString(dateTimeStart As Date, dateTimeEnd As Date) As String
'*********************************************************************
' Function ElapsedTimeString(dateTimeStart As Date, dateTimeEnd As Date) As String
' Returns the time elapsed between a starting Date/Time and an ending
' Date/Time formatted as a string that looks like this:
' "10 days, 20 hours, 30 minutes, 40 seconds".
'*********************************************************************
Dim interval As Double, str As String, days As Variant
Dim hours As String, minutes As String, seconds As String
If IsNull(dateTimeStart) = True Or _
IsNull(dateTimeEnd) = True Then Exit Function
interval = dateTimeEnd - dateTimeStart
days = Fix(CSng(interval))
hours = Format(interval, "h")
minutes = Format(interval, "n")
seconds = Format(interval, "s")
' Days part of the string
str = IIf(days = 0, "", _
IIf(days = 1, days & " Day", days & " Days"))
str = str & IIf(days = 0, "", _
IIf(hours & minutes & seconds <> "000", ", ", " "))
' Hours part of the string
str = str & IIf(hours = "0", "", _
IIf(hours = "1", hours & " Hour", hours & " Hours"))
str = str & IIf(hours = "0", "", _
IIf(minutes & seconds <> "00", ", ", " "))
' Minutes part of the string
str = str & IIf(minutes = "0", "", _
IIf(minutes = "1", minutes & " Minute", minutes & " Minutes"))
str = str & IIf(minutes = "0", "", IIf(seconds <> "0", ", ", " "))
' Seconds part of the string
str = str & IIf(seconds = "0", "", _
IIf(seconds = "1", seconds & " Second", seconds & " Seconds"))
ElapsedTimeString = IIf(str = "", "0", str)
End Function
I am a novice when it comes to VBA programming, but I feel pretty confident in normal Access functionality. I'm stuck when it comes to conditional formatting. I've developed a program that prints a report of how long a work order has been open. However, I would like to make WO's that have been open for less than 1 day to print in 1 color and those that have been open more than 1 day, but less than 3 days to print in another color. There are 2 catches to this:
1) The "# of days open" field displays the calculation as a text string
2) There is another field called MINOR_MAJOR that I want to play a role in this report.
If the WO is MINOR and is also less than 1 day, it should be bolded. If this WO is MAJOR and between 1 and 3 days, it should be bolded (another color). Anything outside this metric can be normal text. Here's the code I've been using to get the calculation to show as days, hours, minutes, and seconds. Can I build these conditions into this code? Thanks for any help!!
Public Function ElapsedTimeString(dateTimeStart As Date, dateTimeEnd As Date) As String
'*********************************************************************
' Function ElapsedTimeString(dateTimeStart As Date, dateTimeEnd As Date) As String
' Returns the time elapsed between a starting Date/Time and an ending
' Date/Time formatted as a string that looks like this:
' "10 days, 20 hours, 30 minutes, 40 seconds".
'*********************************************************************
Dim interval As Double, str As String, days As Variant
Dim hours As String, minutes As String, seconds As String
If IsNull(dateTimeStart) = True Or _
IsNull(dateTimeEnd) = True Then Exit Function
interval = dateTimeEnd - dateTimeStart
days = Fix(CSng(interval))
hours = Format(interval, "h")
minutes = Format(interval, "n")
seconds = Format(interval, "s")
' Days part of the string
str = IIf(days = 0, "", _
IIf(days = 1, days & " Day", days & " Days"))
str = str & IIf(days = 0, "", _
IIf(hours & minutes & seconds <> "000", ", ", " "))
' Hours part of the string
str = str & IIf(hours = "0", "", _
IIf(hours = "1", hours & " Hour", hours & " Hours"))
str = str & IIf(hours = "0", "", _
IIf(minutes & seconds <> "00", ", ", " "))
' Minutes part of the string
str = str & IIf(minutes = "0", "", _
IIf(minutes = "1", minutes & " Minute", minutes & " Minutes"))
str = str & IIf(minutes = "0", "", IIf(seconds <> "0", ", ", " "))
' Seconds part of the string
str = str & IIf(seconds = "0", "", _
IIf(seconds = "1", seconds & " Second", seconds & " Seconds"))
ElapsedTimeString = IIf(str = "", "0", str)
End Function