Access database functions

The following code is failing because the stored procedure contains a SQL query that implements custom VBA function in the WHERE clause.  How do I make this work?

         Dim comm As OleDbCommand = ADOPlus.SetCommand("[ActiveBillboards]",  System.Data.CommandType.StoredProcedure, Source)
         Dim reader As OleDbDataReader = comm.ExecuteReader

         With reader
            If .HasRows Then
               While .Read()

               End While
            End If
         End With

         ADOPlus.Params.SetStoredProcedureParams(comm)
Ray TurnerSenior ConsultantAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
You'd have to either rewrite the query to not use that custom function, or determine exactly what the [ActiveBillboards] query does (as well as the custom VBA function), and recreate that functionality in your ASP.NET program. IMO, recreating the functionality is the better idea, since you've have full control over what is happening.

Can you show the query, and also show the code for the custom VBA Function? That might help us to give a better response.
1

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ray TurnerSenior ConsultantAuthor Commented:
Thanks!  Here's SQL and the code.  I'm thinking about removing the function from the WHERE clause; which should make the SQL fly.  Perform the filtering on the client.  What do you think?

Do Access have any intrinsic functions that can do some (or all) of what the FrequencyInRange function is doing?

SELECT Billboards.id, Billboards.navigateurl, Billboards.image
FROM Billboards
WHERE (((Billboards.DisplayStartDate)<=Date()) AND ((Date())<=[Billboards].[DisplayThruDate]) AND ((Billboards.inactive)=False)) OR (((Billboards.Continuous)=True) AND ((Billboards.inactive)=False)) OR (((Billboards.inactive)=False) AND ((FrequencyInRange([Billboards].[Frequency],[Billboards].[EffectiveMonths],Date(),[Billboards].[daysinadvance]))<>False))
ORDER BY Billboards.ImportanceLevel DESC , Billboards.DisplayStartDate, Billboards.Continuous;

-----------------------------------------------------------------------------------------------------------------------------------------------
Option Compare Database

Public Function FrequencyInRange(Frequency As String, EffectiveMonths As String, CurrentDate As Date, DaysInAdvance As Integer) As Boolean
    FrequencyInRange = False
   
    If Len(Frequency) <> 0 Then
        Dim EffMonths() As String
        Dim EffFreqs() As String
   
        EffMonths = Split(EffectiveMonths, ",")
        EffFreqs = Split(Frequency, ",")
       
        For Each EffFreq In EffFreqs
            For Each EffMonth In EffMonths
                Dim CalculatedDate As Date
               
                CalculatedDate = FrequencyToDate(EffFreq, CInt(EffMonth))
               
                If InRange(Date, DateAdd("d", -DaysInAdvance, CalculatedDate), CalculatedDate) Then
                    FrequencyInRange = True
                End If
            Next
        Next
    End If
End Function

Private Function FrequencyToDate(reccurrence As Variant, monthNumber As Integer) As Date
    Dim daynumber As Integer
    Dim firstCharacter As String
    Dim dayAbbrev As String

    firstCharacter = Mid(Trim(reccurrence), 1, 1)
   
    FrequencyToDate = Date

    If IsNumeric(firstCharacter) Then
         Dim ordinal As Integer
         Dim kounter As Integer

         ordinal = CInt(Mid(Trim(reccurrence), 1, 1))
         dayAbbrev = Mid(Trim(reccurrence), 2)
         kounter = 0
         
         daynumber = 1

         Do
            FrequencyToDate = DateSerial(DatePart("yyyy", Date), monthNumber, daynumber)

            If Mid(WeekdayName(Mid(Trim(Weekday(FrequencyToDate)), 1, 2)), 1, 2) = dayAbbrev Then
                kounter = kounter + 1
            End If

            daynumber = daynumber + 1
         Loop Until kounter = ordinal
    End If
     
    If Mid(firstCharacter, 1, 1) = "L" Then
        dayAbbrev = Mid(Trim(reccurrence), 2)

        daynumber = 1

        FrequencyToDate = DateAdd("m", 1, DateSerial(DatePart("yyyy", Date), monthNumber, daynumber))

        Do
            daynumber = daynumber - 1
           
            FrequencyToDate = DateSerial(DatePart("yyyy", Date), monthNumber, daynumber)
        Loop Until Mid(WeekdayName(Mid(Trim(Weekday(FrequencyToDate)), 1, 2)), 1, 2) = dayAbbrev
    End If
End Function

Private Function InRange(testValue As Variant, lowerRange As Variant, upperRange As Variant) As Boolean
    InRange = (testValue >= lowerRange And testValue <= upperRange)
End Function
0
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
I'm thinking about removing the function from the WHERE clause; which should make the SQL fly.
That would be my suggestion.

Access doesn't have any builtin functionality that would duplicate what you're doing in those functions.
0
Ray TurnerSenior ConsultantAuthor Commented:
Thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.