Share via

Runtime Errors are not matching

Mark McCumber 436 Reputation points
2021-08-04T15:16:55.853+00:00

I have the following code to retrieve a specific record based on Game ID and date.
Public Function Most_Recent_By_GameID_And_Date(ByVal lngGameID As Long, _
ByVal dtmDate As Date) _
As ADODB.Recordset
'Purpose: Finds the days the games are drawn
'Parameters: lngGameID As Long - Game ID number
'Returns: A recordset

    On Error GoTo Most_Recent_By_GameID_And_Date_Err  
    Set dbs = CurrentDb  
      
    strSQL = "SELECT TOP 1 * FROM tblActual_Draw " & _  
             "WHERE (((tblActual_Draw.GameID) = " & [lngGameID] & ") " & _  
             "AND ((tblActual_Draw.Drw_Date) = #" & [dtmDate] & "#)) " & _  
             "ORDER BY tblActual_Draw.Drw_Date DESC;"  
              
    Set rsData = dbs.OpenRecordset(strSQL, adOpenDynamic)  
  
    With rsData  
        If .RecordCount > 0 Then  
            'Populate RecordSet  
            Set Most_Recent_By_GameID_And_Date = rsData  
        Else  
            Set Most_Recent_By_GameID_And_Date = Nothing  
        End If  
    End With  
      
Most_Recent_By_GameID_And_Date_Exit:  
    On Error Resume Next  
    Exit Function  
      
Most_Recent_By_GameID_And_Date_Err:  
    'Log error  
    Call LogError(Err.Number, _  
                  Err.Description, _  
                  "modFunctions Function Most_Recent_By_GameID_And_Date", _  
                  Now)  
    Resume Most_Recent_By_GameID_And_Date_Exit  
End Function  
  

I seem to be getting two different types of errors.
120562-lottery-fun-pred-error.png

After I finish the routine I get this error.
120460-lottery-fun-actual-error.png

I don't understand why.

Can someone help me. I haver used such functions in the past and didn't have any problems.

Thanks,

Microsoft 365 and Office | Access | Development
0 comments No comments

Answer accepted by question author

Mark McCumber 436 Reputation points
2021-08-05T15:34:28.263+00:00

I found the answer.

I reset the references to:
120826-lottery-fun-ref.png

I modified the VBA code:
Private rsData As Recordset

Public Function Most_Recent_By_GameID_And_Date(ByVal lngGameID As Long, _  
                                               ByVal dtmDate As Date) _  
                                               As Recordset  
    'Purpose:       Finds the days the games are drawn  
    'Parameters:    lngGameID As Long - Game ID number  
    'Returns:       A recordset  
    'Dim rs As Recordset  
    On Error GoTo Most_Recent_By_GameID_And_Date_Err  
    Set dbs = CurrentDb  
      
    strSQL = "SELECT TOP 1 * FROM tblActual_Draw " & _  
             "WHERE (((tblActual_Draw.GameID) = " & [lngGameID] & ") " & _  
             "AND ((tblActual_Draw.Drw_Date) = #" & [dtmDate] & "#)) " & _  
             "ORDER BY tblActual_Draw.Drw_Date DESC;"  
              
    Set rsData = dbs.OpenRecordset(strSQL)  
  
    With rsData  
        If .RecordCount <> 0 Then  
            'Populate RecordSet  
            Debug.Print ("Record Count = " & CStr(rsData.RecordCount))  
            Set Most_Recent_By_GameID_And_Date = rsData  
              
        Else  
            Set Most_Recent_By_GameID_And_Date = Nothing  
        End If  
    End With  
      
Most_Recent_By_GameID_And_Date_Exit:  
    On Error Resume Next  
    Exit Function  
      
Most_Recent_By_GameID_And_Date_Err:  
    'Log error  
    Call LogError(Err.Number, _  
                  Err.Description, _  
                  "modFunctions Function Most_Recent_By_GameID_And_Date", _  
                  Now)  
    Resume Most_Recent_By_GameID_And_Date_Exit  
End Function  

It seems I need to define a RecordSet of object as RecordSet not ADODB.RecordSet.

Thanks

Was this answer helpful?


4 additional answers

Sort by: Most helpful
  1. DBG 11,711 Reputation points Volunteer Moderator
    2021-08-04T19:25:05.573+00:00

    Oh, I think I see it now. I think you're mixing your recordset types: one is DAO and the other is ADO. Either the function you're trying to call requires an ADO recordset, and you're passing it a DAO recordset, or your recordset variable is a DAO recordset, and the recordset returned by your function is ADO.

    Without seeing the entire code, I can't tell you which one it is. Also, do you have Option Explicit in your module?

    Was this answer helpful?

    0 comments No comments

  2. DBG 11,711 Reputation points Volunteer Moderator
    2021-08-04T18:30:37.663+00:00

    Hi. Thanks for the additional info. Just a wild guess, but could you try removing the square brackets around your arguments to see if that helps?

    In other words, where you have:

    "WHERE (((tblActual_Draw.GameID) = " & [lngGameID] & ") " & _
    

    simply use:

    "WHERE (((tblActual_Draw.GameID) = " & lngGameID & ") " & _
    

    Also, do the same with [dtmDate]. Let us know how it goes...

    Was this answer helpful?


  3. Mark McCumber 436 Reputation points
    2021-08-04T18:10:58.147+00:00

    There is no easy way to correct responses.

    Error entry:
    120508-setting-recordset.png

    Before and after execution of function.
    120509-before-setting-rs.png120510-after-setting-rs.png

    Was this answer helpful?

    0 comments No comments

  4. DBG 11,711 Reputation points Volunteer Moderator
    2021-08-04T16:35:31.447+00:00

    Hi. You'll have to step through the code and tell us which lines are highlighted when you get those errors.

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.