+ Reply to Thread
Results 1 to 14 of 14

Error on line set pvtCache = dbRecordset.recordset

Hybrid View

  1. #1
    Registered User
    Join Date
    05-31-2012
    Location
    Dubai, UAE
    MS-Off Ver
    Excel 2010
    Posts
    27

    Exclamation Error on line set pvtCache = dbRecordset.recordset

    Hi,

    I am getting an error "Application-defined or object-defined error : 1004" on the highlighted line below.

    Private Sub CommandButton1_Click()
    Dim PvtCache As PivotCache
    Dim AppAccess  As Access.Application
    Dim dbRecordset As Variant
    
    On Error GoTo errl
    
    Set AppAccess = CreateObject("Access.Application")
    AppAccess.OpenCurrentDatabase Sheet32.Cells(14, 3)
    Set dbRecordset = AppAccess.CurrentDb.OpenRecordset _
    ("_FSTEP_BULK_HSFS_REVENUE")
    Set PvtCache = ActiveWorkbook.PivotCaches.Add _
    (SourceType:=xlExternal)
    
    Set PvtCache.Recordset = dbRecordset
    With PvtCache
        .CreatePivotTable TableDestination:=Range("A43"), _
            TableName:="Performance"
    End With
    
    With ActiveSheet.PivotTables("Performance")
        .SmallGrid = False
        With .PivotFields("C_4")
            .Orientation = xlRowField
            .Position = 1
        End With
        With .PivotFields("C_2")
            .Orientation = xlColumnField
            .Position = 1
        End With
        With .PivotFields("C_7")
            .Orientation = xlDataField
            .Position = 1
        End With
    End With
    Exit Sub
    errl:
    MsgBox Err.Number & " " & Err.Description
    AppAccess.CloseCurrentDatabase
    Set AppAccess = Nothing
    Set dbRecordset = Nothing
    Set PvtCache = Nothing
    End Sub
    I cannot use ADODB or DAO because I am on Win 64-bit machine. But it should still work I assume so what is it that I am doing wrong here?

  2. #2
    Registered User
    Join Date
    05-31-2012
    Location
    Dubai, UAE
    MS-Off Ver
    Excel 2010
    Posts
    27

    Re: Error on line set pvtCache = dbRecordset.recordset

    Can anyone please help me out with this?

  3. #3
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Error on line set pvtCache = dbRecordset.recordset

    Quote Originally Posted by fadydaddy View Post
    I cannot use ADODB or DAO because I am on Win 64-bit machine.
    what do you mean by that? the recordset has to be one or the other, and you need ADO as far as I know (you have DAO)
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  4. #4
    Registered User
    Join Date
    05-31-2012
    Location
    Dubai, UAE
    MS-Off Ver
    Excel 2010
    Posts
    27

    Re: Error on line set pvtCache = dbRecordset.recordset

    Whenever I declare Dim dbRecordset as ADODB.Recordset, it doesn't compile. However I am able to do my operations if I use the Access Object Library. But why am I getting this error?

  5. #5
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Error on line set pvtCache = dbRecordset.recordset

    you need to set a reference to the 'microsoft activex data objects library' to use ADO. like I said, you can't use a dao recordset for a pivotcache as far as I know.

  6. #6
    Registered User
    Join Date
    05-31-2012
    Location
    Dubai, UAE
    MS-Off Ver
    Excel 2010
    Posts
    27

    Re: Error on line set pvtCache = dbRecordset.recordset

    Well, that I can't. Win 64 bit does not compile ADO.

  7. #7
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Error on line set pvtCache = dbRecordset.recordset

    that's just not true.

  8. #8
    Registered User
    Join Date
    05-31-2012
    Location
    Dubai, UAE
    MS-Off Ver
    Excel 2010
    Posts
    27

    Re: Error on line set pvtCache = dbRecordset.recordset

    Private Sub CommandButton1_Click()
    Dim cnnConn As ADODB.Connection
    Dim rstRecordset As ADODB.Recordset
    Dim cmdCommand As ADODB.Command
     
    ' Open the connection.
    Set cnnConn = New ADODB.Connection
    With cnnConn
     .ConnectionString = _
     "Provider=Microsoft.Jet.OLEDB.4.0"
     .Open "G:\Departments\Circulation\MIS\HANDOVER\MIS FORMAT V2\MIS BILLBOARD VERSIONS 3.X\MIS DATABASE.accdb"
    End With
     
    ' Set the command text.
    Set cmdCommand = New ADODB.Command
    Set cmdCommand.ActiveConnection = cnnConn
    With cmdCommand
     .CommandText = "Select * from _FSTEP_BULK_HSFS_REVENUE"
     .CommandType = adCmdText
     .Execute
    End With
     
    ' Open the recordset.
    Set rstRecordset = New ADODB.Recordset
    Set rstRecordset.ActiveConnection = cnnConn
    rstRecordset.Open cmdCommand
     
    ' Create a PivotTable cache and report.
    Set objPivotCache = ActiveWorkbook.PivotCaches.Add( _
     SourceType:=xlExternal)
    Set objPivotCache.Recordset = rstRecordset
    With objPivotCache
     .CreatePivotTable TableDestination:=Range("A3"), _
     TableName:="Performance"
    End With
     
    With ActiveSheet.PivotTables("Performance")
     .SmallGrid = False
     With .PivotFields("Pressure")
     .Orientation = xlRowField
     .Position = 1
     End With
     With .PivotFields("Speed")
     .Orientation = xlColumnField
     .Position = 1
     End With
     With .PivotFields("Time")
     .Orientation = xlDataField
     .Position = 1
     End With
    End With
     
    ' Close the connections and clean up.
    cnnConn.Close
    Set cmdCommand = Nothing
    Set rstRecordset = Nothing
    Set cnnConn = Nothing
    
    End Sub
    If I use this code (with references set to ADODB library 6.0) then I get runtime error 3706 for application defined or object defined error on the line
    .Open "G:\Departments\Circulation\MIS\HANDOVER\MIS FORMAT V2\MIS BILLBOARD VERSIONS 3.X\MIS DATABASE.accdb"

  9. #9
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Error on line set pvtCache = dbRecordset.recordset

    you need to use the microsoft.ace.oledb.12.0 provider.

  10. #10
    Registered User
    Join Date
    05-31-2012
    Location
    Dubai, UAE
    MS-Off Ver
    Excel 2010
    Posts
    27

    Re: Error on line set pvtCache = dbRecordset.recordset

    https://www.google.ae/#hl=en&safe=of...w=1024&bih=628you will find a lot of issues win Win 64 under these results

  11. #11
    Registered User
    Join Date
    05-31-2012
    Location
    Dubai, UAE
    MS-Off Ver
    Excel 2010
    Posts
    27

    Re: Error on line set pvtCache = dbRecordset.recordset

    I don't have that. You see I am sitting on a Citrix desktop compiling this. There is no reference for that available.

  12. #12
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Error on line set pvtCache = dbRecordset.recordset

    it's not a reference - it's the provider string you should use instead of microsoft.jet.oledb.4.0

  13. #13
    Registered User
    Join Date
    05-31-2012
    Location
    Dubai, UAE
    MS-Off Ver
    Excel 2010
    Posts
    27

    Re: Error on line set pvtCache = dbRecordset.recordset

    Quote Originally Posted by JosephP View Post
    it's not a reference - it's the provider string you should use instead of microsoft.jet.oledb.4.0
    This solved it. Thank you for your patience and help!

  14. #14
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Error on line set pvtCache = dbRecordset.recordset

    are you telling me it doesn't work? I already told you not to use the Jet provider

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1