datareports in vb6
I have problems with Datareports in vb6.
I made a Dataenvironment with the command to access the rows I want 开发者_如何学Cto show Then I made the Datareport and in the datamember property I used the Dataenvironment created.
If I use the code:
Load datareport
datareport.Show 1
Then if I open the report and then I add more rows to the table, when I open the report again it doesnt change. I see the same output.
I read that I should reopen the connection. How is the correct way to open the connection for the datareport and then close it so that the MS Access database is not locked.
Not sure about exact sequence of actions in Access, but Load
command in VB6, when presented with a global object name, only loads it if it's not already loaded. You apparently need to Unload datareport
at a certain moment (like, when you close it).
First, you don't have to use Load
explicitly for forms/reports, just accessing a property/method loads the instance.
Second, don't use the global instances of forms/reports -- Form1, DataReport1 -- this is legacy from MS Access compatibility and is strongly discouraged. You can create separate instances of forms/reports like regular classes with operator New
-- Set MyInstance = New DataReport1
In your case easiest would be to replace your load/show code with something like this:
With New DataReport1
.Show vbModal
End With
where DataReport1 is the name of your report class. This snippet each time creates a new instance of DataReport1 and shows it modally. The newly created instance is terminated when the user dismisses the UI window.
精彩评论