I have been struggling with a time format issue in SSRS. What I have so far is that seconds are listed with 00:00:15 but minutes like 15:25 instead of 00:15:25. I’ve been playing with it for a while now, but somehow it won’t show, no matter where I put the "00:" &
This is my code
=IIF(Sum(Fields!ActualTime.Value)/Fields!EventCount.Value < 1,"", IIF((Sum(Fields!ActualTime.Value)/Fields!EventCount.Value)/60 < 1, "00:00:" & (Sum(Fields!ActualTime.Value)/Fields!EventCount.Value), IIF((Sum(Fields!ActualTime.Value)/Fields!EventCount.Value)/3600 >= 1, ((Sum(Fields!ActualTime.Value)/Fields!EventCount.Value) - (Sum(Fields!ActualTime.Value)/Fields!EventCount.Value) mod 3600)/3600 & ":","") & IIF((Sum(Fields!ActualTime.Value)/Fields!EventCount.Value) mod 3600 >= 1, ((Sum(Fields!ActualTime.Value)/Fields!EventCount.Value) mod 3600 - (Sum(Fields!ActualTime.Value)/Fields!EventCount.Value) mod 3600 mod 60)/60 & ":","") & (Sum(Fields!ActualTime.Value)/Fields!EventCount.Value) mod 3600 mod 60))
Also 1 second, minute or hour is listed without a leading 0. Like this: 01:01:01
Please advise. Thanks in advance.
You can set the time format through the expression for a text fields. Click on the textbox and press f4. Go to the format and click on the dropdown and then click on expression.
In the expression u can write something like this.
=switch("More than one hour","HH:mm:ss",
"less than one hour and more than a minute","MM:ss",
"Less than one minute","SS",)
U have to put ur conditions in the part where I have mentioned the times ('more than one year etc.').
let me know if still ur facing any problems.
I couldnt get this to work. So after searching the web for a few days, i found a Function here on stackoverflow that converts seconds to hh:mm:ss. Since there where 16 fields that needed this calculation i found it easier to use this Function.
Thanks for the answer anyways.
Public Function ConvertSecondsToHourMinSec(ByVal intTotalSeconds) As String
Dim hours As String = INT(intTotalSeconds / 3600)
If Len(hours) < 2 Then
hours = RIGHT(("0" & hours), 2)
End If
Dim mins As String = RIGHT("0" & INT((intTotalSeconds Mod 3600) / 60), 2)
Dim secs As String = Right("0" & INT((intTotalSeconds Mod 3600) Mod 60), 2)
ConvertSecondsToHourMinSec = hours & ":" & mins & ":" & secs
End Function
In the textbox check for < 1 to show nothing and run the custom function otherwise.
=IIF(Sum(Fields!DownTime.Value)/Fields!EventCount.Value < 1,"",Code.ConvertSecondsToHourMinSec(Sum(Fields!DownTime.Value)/Fields!EventCount.Value))
Related
I'm struggeling with a part of code that I want to implement in Microsoft Access.
The required code is used for project asignments.
The code format contains the last 2 numbers of the year + 4 digits which add up until a new year, then the last 2 numbers of the year add up with 1 and the 4 digits start at 1 again.
For example:
2019:
190001 = first task;
190002 = second task;
etc...
2020:
200001 = first task;
200002 = second task;
etc...
Could anybody help me out how to code this in Microsoft Access, preferably by VBA?
This way I can asign the code to a "submit" button to avoid similar numbers.
Thanks!
Formatting your code given an integer could be achieved in several ways, here is one possible method:
Function ProjectCode(ByVal n As Long) As Long
ProjectCode = CLng(Format(Date, "yy") & Format(n, "0000"))
End Function
?ProjectCode(1)
200001
?ProjectCode(2)
200002
?ProjectCode(100)
200100
You probably need to assign the next task id to a project.
So, look up the latest id in use and add 1 to obtain the next task id:
NextTaskId = (Year(Date()) \ 100) * 10000 + Nz(DMax("TaskId", "ProjectTable", "TaskId \ 10000 = Year(Date()) \ 100"), 0) Mod 10000 + 1
Nz ensures that a task id also can be assigned the very first task of a year.
I'm trying to use conditional formatting in SQL Server Reporting Services to change the colour of a row if a value is the same as today's date or not. The column contains the date in the format 13/07/2018. I have also set the field to be in date format (31/01/2000) within place-holder properties.
My expression however is not working
=switch(DateDiff("d", Fields!LastSuccessfulBackupTime00.Value,Format(Now(),"dd/MM/yyyy")) = 0, "Green",DateDiff("d", Fields!LastSuccessfulBackupTime00.Value,Format(Now(), "dd/MM/yyyy")) = 1, "Yellow",DateDiff("d", Fields!LastSuccessfulBackupTime00.Value,Format(Now(), "dd/MM/yyyy")) >= 2, "Red")
The exception that is being thrown is
Argument matching parameter 'DayOfWeek' narrows from 'String' to 'Mcrosoft.VisualBasic.FirstDayOfWeek'
Which is strange because I'm just doing simple datediff calculation to count the number of days between two dates.
Can anyone suggest how to fix this ? Google just says to turn off strict compilation something which I can't find in SQLRS
Try the expression below (expression 1)
=switch(
DateDiff("d", Cdate(Fields!LastSuccessfulBackupTime00.Value),Today()) = 0, "Green"
,DateDiff("d", Cdate(Fields!LastSuccessfulBackupTime00.Value),Today()) = 1, "Yellow"
,DateDiff("d", Cdate(Fields!LastSuccessfulBackupTime00.Value), Today()) >= 2, "Red"
)
Also because Cdate is regional setting dependant you could use Split to create a valid date format for datediff (expression2)
=switch(
DateDiff("d", Fields!LastSuccessfulBackupTime00.Value.Split("/")(2) & "-" & Fields!LastSuccessfulBackupTime00.Value.Split("/")(1) & "-" & Fields!LastSuccessfulBackupTime00.Value.Split("/")(0),Today()) = 0, "Green"
,DateDiff("d", Fields!LastSuccessfulBackupTime00.Value.Split("/")(2) & "-" & Fields!LastSuccessfulBackupTime00.Value.Split("/")(1) & "-" & Fields!LastSuccessfulBackupTime00.Value.Split("/")(0),Today()) = 1, "Yellow"
,DateDiff("d", Fields!LastSuccessfulBackupTime00.Value.Split("/")(2) & "-" & Fields!LastSuccessfulBackupTime00.Value.Split("/")(1) & "-" & Fields!LastSuccessfulBackupTime00.Value.Split("/")(0),Today()) >= 2, "Red"
)
Anyone else having this issue while trying to name a file with the current date and time.
redeemedImgName:String = "soemtext_" + datToday.getFullYear() + "-" + datToday.getMonth() + "-" + datToday.getDay() + "-" + datToday.getHours() + "-" + datToday.getMinutes() + "-" + datToday.getSeconds();
Today is 4/2/2015, but I got the following file name:
"sometext_2015-3-4-15-32-10.jpg"
Yesterday, I was receiving 3/32/2015. Again, anyone else experiencing this issue?
Please advise,
rikixass
datToday.getDay() returns an integer 0-7 corresponding to the day of the week. What you are looking for is datToday.getDate(), which returns the actual calendar number of the day. The months are zero based, so you'd get 3 for April, 4 for may etc.
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/Date.html
I am working with an Access database where I have a form that contains several date entry fields. I have a new user that is used to using a period as a delimiter for dates so instead of "6/22/11" or "6-22-11", they enter "6.22.11". I would like to continue to allow this type of entry, but Access converts "6.22.11" to a time instead of a date. I have tried setting the format on the text box to "Short Date" with no help. I have also tried adding code to the "Lost Focus" event but that is to late since Access has already done the conversion. The "Before Update" event fires before the conversion but will not allow me to change the text in the textbox. Any ideas on how I can allow all three forms of date entry?
your above example
Private Sub Texto0_KeyPress(KeyAscii As Integer)
If Chr(KeyAscii) = "." Then
KeyAscii = Asc("/")
End If
End Sub
works for me.
Another aproximation is play with the BeforeUpdate and AfterUpdate events.
In BeforeUpdate you cannot modify de content of the control, but you can set a flag (a variable defined at module/form level) in the AfterUpdate event and change the content: it will trigger again the BeforeUpdate, but in this case, because is flagged you sould ignore it and unflag.
http://office.microsoft.com/en-us/access-help/control-data-entry-formats-with-input-masks-HA010096452.aspx
Input Mask.
I wrote the following function for a user who was used to entering 6 and 8 digit dates in input masks by just typing a string of numbers with no delimiter. You should be able to modify it for your purposes:
'---------------------------------------------------------------------------
' Purpose : Enables entry of 8-digit dates with no delimiters: 12312008
' Usage : Set OnChange: =DateCtlChange([Form].[ActiveControl])
' 8/ 6/09 : Allow entry of 6-digit dates with no delimiters
' (year 2019 and 2020 must still be entered as 8-digit dates)
'---------------------------------------------------------------------------
Function DateCtlChange(DateCtl As TextBox)
Dim s As String, NewS As String
On Error GoTo Err_DateCtlChange
s = DateCtl.Text
Select Case Len(s)
Case 6
If s Like "######" Then
If Right(s, 2) <> "19" And Right(s, 2) <> "20" Then
NewS = Left(s, 2) & "/" & Mid(s, 3, 2) & "/" & Mid(s, 5, 2)
End If
End If
Case 8
If s Like "########" Then
NewS = Left(s, 2) & "/" & Mid(s, 3, 2) & "/" & Mid(s, 5, 4)
End If
End Select
If IsDate(NewS) Then
DateCtl.Text = NewS
DateCtl.SelStart = Len(DateCtl.Text)
End If
Exit_DateCtlChange:
Exit Function
Err_DateCtlChange:
Select Case Err.Number
'Error 2101 is raised when we try to set the text to a date
' that fails the date control's validation
Case 2101 'The setting you entered isn't valid for this property.
'Log error but don't show user
Case Else
'Add your custom error logging here
End Select
Resume Exit_DateCtlChange
End Function
Access uses the system date and time format to determine how to translate a value. Another option - that would affect every program on this user's computer - is this: http://office.microsoft.com/en-us/access-help/change-the-default-date-time-number-or-measurement-format-HA010351415.aspx?CTT=1#BM2
Alternatively you can use spaces instead of slashes in dates in Access. Thus the user can use the left hand on the space bar and use the right hand on the numeric keyboard. I feel this is much easier to use than either the slash or the hyphen.
In my job, I have inherited an Access 97 database. This database is very unstable and I need to remedy that in one way or another. I have been trying to go through and debug the current version so that I can migrate it to 2007. I have run across some code that the compiler doesn't like and not sure how to fix it...here is the code:
Function DaysInMonth(ByVal D As Date) As Long
' Requires a date argument because February can change
' if it's a leap year.
Select Case Month(D)
Case 2
If LeapYear(Year(D)) Then
DaysInMonth = 29
Else
DaysInMonth = 28
End If
Case 4, 6, 9, 11
DaysInMonth = 30
Case 1, 3, 5, 7, 8, 10, 12
DaysInMonth = 31
End Select
End Function
I get a compile error: Sub or Function not defined and it highlights the first "LeapYear".
Any help at all would be greatly appreciated! Thanks!
LeapYear is another function or procedure that appears not be present in your modules or has been made Private. LeapYear isn't a VBA function. There must have been a function that takes a year Year(D) and returns TRUE or FALSE if it's a leapyear. either insert one or set the existing one to Public
Edit:You could use IsLeapYear but change to 'LeapYear' and call using IsLeapYear(D)
The code in question is idiotic -- it was clearly written by somebody who didn't have a clue about VBA dates, which already know everything that is needed without needed to encode this crap into a CASE SELECT.
This expression will get you the number of days in a month:
Day(DateAdd("m", 1, DateValue(Month(Date()) & "/1/" & Year(Date()))) - 1)
What this does is get the first of the current month, adds a month to it (for the first of the next month), and then subtracts 1 from it. Since the integer part of the VBA date type is the day part, that will get you the last day of the current month. Then you take the result and pull the day out with the Day() function.
Coding that up as a function:
Function DaysInMonth(ByVal dteDate As Date) As Integer
Dim dteFirstOfMonth As Date
Dim dteLastOfMonth As Date
dteFirstOfMonth = DateValue(Month(dteDate) & "/1/" & Year(dteDate))
dteLastOfMonth = DateAdd("m", 1, dteFirstOfMonth) - 1
DaysInMonth = Day(dteLastOfMonth)
End Function
You could also code this up using the fact that the DateSerial() function treats the zeroth day as the last of the previous month:
Function DaysInMonth(ByVal dteDate As Date) As Integer
Dim dteOneMonthFromDate As Date
Dim dteLastOfThisMonth As Date
dteOneMonthFromDate = DateAdd("m", 1, dteDate)
dteLastOfThisMonth = DateSerial(Year(dteOneMonthFromDate), Month(dteOneMonthFromDate), 0)
DaysInMonth = Day(dteLastOfThisMonth)
End Function
But that doesn't make it any shorter...
None of this requires figuring out leap year rules -- those are built into the VBA date type.
And, of course, the function should not return a Long, but an Integer, since the maximum value it can ever return is 31.
LeapYear may not be your only issue.
In Access '97, go to the VBA editor and click "Tools/References":
Look in the references of your '97 project and see what DLLs are listed.
A screen will appear that shows you the ActiveX DLLs that can be used for the project. The ones that are checked are the ones currently used:
Odds are there is a DLL there that needs to be referenced in your new 2007 database.