VB Function to return records based on a date parameter & date field OR another date field (Visual Studio 2008, Report Builder 3.0, SharePoint Lists)

StackOverflow https://stackoverflow.com/questions/15750728

Question

Another question sourced from this tricky environment and my inexperience. It seems like VB Functions are the only way I can deliver on some of these report requirements.

I have a situation where a user wants to see data in a report as follows:

The general requirement is this: when the report is initialized, no data is shown - the user must put in a parameter. This is complete. The parameter is a date parameter - if the date is blank, all items in the list will be returned. If a date is entered for the parameter, all items of typeA or typeB equal to or greater than the data param must be returned.

More specifically, this is what I am trying to accomplish: Return all items where typeA_date is not blank and is greater than or equal to the date entered in the parameter OR return all items where typeB_date is not blank and is greater than or equal to the date entered in the parameter.

Here is the code I have, but it is returning an error:

Function dtComprRtrn(ByVal awardField As String, ByVal suspendField As String, ByVal chkDtField As String) As Boolean
    If chkDtField Is Nothing Then
        Return True
    End If
    Dim awardDate As Date
    Dim suspendDate As Date
    If (IsDate(awardDate)) Then
        chkDtField = Convert.ToDateTime(awardDate)
    ElseIf (IsDate(suspendDate)) Then
        chkDtField = Convert.ToDateTime(suspendDate)
    Else
        Return False
    End If
    If awardDate >= chkDtField Then
        Return True
    Else
        If suspendDate >= chkDtField Then
            Return True
        Else
            Return False
        End If
    End If

The error is this:

"An unexpected error occurred while compiling expressions. Native compiler return value: ‘[BC30289] Statement cannot appear within a method body. End of method assumed"

I don't have much experience in this area, or in integrating a function into Report Builder, and I am eternally grateful for any assistance that may be provided. Thank you much!

Was it helpful?

Solution

Here is the final code solution that was implemented and appears to be working:

Function dtComprRtrn(ByVal awardField As String, ByVal suspendField As String, ByVal chkDtField As String) As Boolean
    If chkDtField Is Nothing Then
        Return True
    End If
    Dim compareDate As Date = DateTime.MinValue
    Dim chkDtDate As Date = DateTime.MinValue
    ' Check to see if input string chkDtField is a date
    If (IsDate(chkDtField)) Then
        chkDtDate = Convert.ToDateTime(chkDtField)
    End If
    ' Check to see if either awardField or suspendField is a date
    ' if not then return false
    If (IsDate(awardField)) Then
        compareDate = Convert.ToDateTime(awardField)
    ElseIf (IsDate(suspendField)) Then
        compareDate = Convert.ToDateTime(suspendField)
    Else
        Return False
    End If
    ' Now we know we have a date in compareDate
    ' and we know that chkDtDate is at least DateTime.MinValue
    ' so if chkFtField was blank then this comparison will always
    ' work if we have a valid date for awardField or suspendField
    If compareDate >= chkDtDate Then
        Return True
    Else
        Return False
    End If
End Function
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top