test

minette

Board Regular
Joined
Jul 8, 2005
Messages
237
Hi everyone, I'm stuck on a little problem. I am running some Access queries and tables from Excel vba, and returning the results to specific cells in Excel. However, although the queries run correctly, the acCmdSelectAllRecords always returns the number of rows from the first query. These should all be different. Any ideas anyone? My code is below:


Code:
Sub TESTING() 
    Dim accApp As Object 
    Set accApp = GetObject("c:\Property\Property.mdb") 
    
'Query1 - should return 68 rows
    accApp.DoCmd.OpenQuery "022 Property Query" 
    accApp.DoCmd.RunCommand acCmdSelectAllRecords 
    accApp.DoCmd.RunCommand acCmdCopy 
    Workbooks("Property Report.xls").Sheets("Input Sheet").Activate 
    With Sheets("Input Sheet") 
        .Range("A99").Activate 
        .PasteSpecial 
    End With 
 
'Query2 - should return 8 rows   
    accAppDoCmd.OpenQuery "021 Property Query" 
    accApp.DoCmd.RunCommand acCmdSelectAllRecords 
    accApp.DoCmd.RunCommand acCmdCopy 
    Workbooks("Property Report.xls").Sheets("Input Sheet").Activate 
    With Sheets("Input Sheet") 
        .Range("A107").Activate 
        .PasteSpecial 
    End With 
    
'Query3 - should return 4 rows
    accApp.DoCmd.OpenTable "304 Property Table" 
    accApp.DoCmd.RunCommand acCmdSelectAllRecords 
    accApp.DoCmd.RunCommand acCmdCopy 
    Workbooks("Property Report.xls").Sheets("Input Sheet").Activate 
    With Sheets("Input Sheet") 
        .Range("A125").Activate 
        .PasteSpecial 
    End With 
    
    accApp.DoCmd.Quit 
    Set accApp = Nothing 
End Sub
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.

Forum statistics

Threads
1,214,376
Messages
6,119,174
Members
448,870
Latest member
max_pedreira

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top