VBA Select MAX dataset from database


Sub test()
    Dim cnn As New ADODB.Connection
    Dim rst As New ADODB.Recordset
    Dim oCm As New ADODB.Command
    cnn.Open "Provider=Microsoft.ACE.OLEDB.12.0;" & _
             "Data Source=C:\CovBonds\CB.mdb"
    Dim strRange As String
   
    strRange = "SELECT MAX([ProgramID]) FROM dbo_tblCoveredBonds;"
    rst.Open strRange, _
             cnn, adOpenStatic
    rst.MoveFirst
    Sheets("Misc").Range("R2").Value = rst.RecordCount
    Sheets("Misc").Range("Q2").Value = rst.Fields(0).Value
 
End Sub