Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA dp refresh solution please

Status
Not open for further replies.

norty303

Technical User
Jul 23, 2003
416
GB
Hi. I've got a short bit of VBA that someone kindly provided from another forum but it doesn't run giving an error:

runtime error 91

Object variable or with block variable not set


The code is:

Private Sub Document_Open()
DIM ThisDocument as Document
ThisDocument.DataProviders("YourDPNameHere").Refresh
End Sub



As I'm unfamiliar with VBA I'm unable to debug it. Can anyone here help. It's purpose is to refresh just one DP in the report on open.

Many thanks
 
If you would like to refresh you document, use this way
Set Doc = ActiveDocument
Doc.Refresh
 
Norty,

You cannot get a reference to the ActiveDocument in the Document Open event since the Document is yet to opened and made active. Check out this code and it should get you what you are after..

Code:
Private Sub Document_Activate()
    ActiveDocument.DataProviders.Item(1).Refresh
End Sub

The above code will refresh the 1st DP when the document is opened.

Regards,
Sri
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top