Refreshing a database query

G

Guest

Hi all ,
i am not too good at vba but i have a command button that activates to
refresh a database query frm other worksheets then refresh a pivot table(data
is from query) follow by doing a Calculate

The database query always encounter 1 problem
My database query cant refresh after i press it for second time.
its like the table is copied onto the sheet and cannot be refresh.
Anyone can highlight me the problemes?

thanks
below my code for the command button.

Private Sub RefData_Click()
Sheets("BalancePO").Activate
Selection.QueryTable.Refresh BackgroundQuery:=False

Sheets("POTable").Activate
Set pvtTable = Worksheets("POTable").Range("A1").PivotTable
pvtTable.SourceData = "Database"
pvtTable.RefreshTable

Sheets("EL2 Summary").Activate
Range("C19").Select
Application.MaxChange = 0.001
ActiveWorkbook.PrecisionAsDisplayed = False
Calculate
Calculate
End Sub
 
T

Tom Ogilvy

Are you sure the refreshed table is named database and database includes the
entire table?
 
G

Guest

i define the name "Database"
its the range of the query table.

Database=OFFSET(BalancePO!$A$1,0,0,COUNTA(BalancePO!$A:$A),7)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top