Hi, I am a new member in this site. I am also just learning VB6. I made some progress in programming a report generator for my farm. However, after having designed a report using Data Report designer, I keep getting the same result or reports repeatedly although I have changed some parameters already. There's a need to click on the command button twice or reprocess the report twice just to get the desired data. Otherwise, old data on the reports remains which was actually the result of previous report processing. There seems to be a cache that keeps throwing the same data repeatedly although another recordsets of data have already been saved in the source table. I use Data Environment as data source for my report, Data Access Object for my forms and MS Access as database repository. Thanks.

Hi,

Before showing the report just Refresh it..:

DataReport1.Refresh
DataReport1.Show

Regards
Veena

Veena, thanks for the prompt reply. But, I already tried that and no success.

Hi,

u can try this :

dataenv.Command1.Open
dataenv.Command1.Requery
DataReport1.Refresh
DataReport1.Show

Change the dataenv and command names..

Regards
Veena

Veena, thanks again. Tried that too, still no luck.

I don't know if you found a solution but I fixed this by setting the Report Data Source to nothing and then assigning it again to the Data Environment like this:

Set DataReport1.DataSource = Nothing
Set DataReport1.DataSource = DataEnvironment1

Do this before doing anything and that should fix the problem.

Rich, Thanks for your reply. I just tried it. Didn't work for me. I fetch a set of data records that could fill up to 7 columnar pages (e.g. feed requirements of a huge number of sows. very important for us farmers to forecast budgeting and raw materials). I think the size of the data being generated is pushing MS access or MS Jet4.0 provider to the limit. (not sure). I tried for the past few days to do all sorts of initializing the data environment, tables and data object but causing another error "failing to get row sets" (whatever). In the meantime, I am just contented with clicking the command button one more time as if refreshing the displayed report the 2nd time. Hey, that is what is available in Crystal Reports but unfortunately it's not available in my town as yet. At least, Im happy enough for now clicking my Ok button twice. Really appreciate your concern to newbies like me.

I don't know if you found a solution but I fixed this by setting the Report Data Source to nothing and then assigning it again to the Data Environment like this:

Set DataReport1.DataSource = Nothing
Set DataReport1.DataSource = DataEnvironment1

Do this before doing anything and that should fix the problem.

Maybe somehow when you show the report, it's not updated yet, maybe it gets only updated after you click the ok(or whatever). If you send your code, someone might be able to catch your problem.

Here is that part of the code where I show my datareport1:

Private Sub cmdOk_Click()
'========================
Dim nYear As Integer

nYear = nVal(cmbFromYear.Text)
isDiscounted = chkDiscounted.Value
isSumReport = chkSumReport.Value

dStartDate = cmbFromMonth.Text & " 01, " & cmbFromYear.Text
dStartDate = Format(dStartDate, "MM/dd/YYYY")       
dEndDate = cmbEndMonth.Text & " 28, " & cmbEndYear.Text   'part of determining
dEndDate = Format(dEndDate, "MM/dd/YYYY")                        'last date of the month.
dEndDate = xLastDay(dEndDate)                                           'Ending date to report

'Check correctnext of month entered
If Trim(cmbFromMonth.Text) = "" Or Not MonthNameOk(cmbFromMonth.Text) Then
     MsgBox "Enter a proper starting month name! ", vbExclamation, "Wrong entry"
     cmbFromMonth.SetFocus
     Exit Sub
End If

If Trim(cmbEndMonth.Text) = "" Or Not MonthNameOk(cmbEndMonth.Text) Then
     MsgBox "Enter a proper ending month name! ", vbExclamation, "Wrong entry"
     cmbEndMonth.SetFocus
     Exit Sub
End If

If cmbEndMonth.ListIndex < cmbFromMonth.ListIndex And _
       nVal(cmbEndYear.Text) <= nVal(cmbFromYear.Text) Then
       MsgBox "Starting month cannot be greater than ending month!", vbExclamation, "Wrong entry"
       Exit Sub
End If

'Check correctness of year number entered.
If nVal(cmbFromYear.Text) < Year(Date) Then
     MsgBox "Enter a proper starting year!", vbExclamation, "Wrong entry"
     Exit Sub
End If

If nVal(cmbEndYear.Text) < Year(Date) Then
     MsgBox "Enter a proper ending year!", vbExclamation, "Wrong entry"
     Exit Sub
End If

If nVal(cmbEndYear.Text) < nVal(cmbFromYear.Text) Then
     MsgBox "Starting year cannot be later than ending year!", vbExclamation, "Wrong entry"
     Exit Sub
End If

Me.MousePointer = vbHourglass

'Clean report file or RepoDetails table -> RepoDetails

With dtaRepoDetails.Recordset
    If .RecordCount <> 0 Then
        .MoveFirst
    End If
    While .EOF = False
          .Delete             'Delete all records used by       
          .MoveNext        'previous reporting.  This DAO table   
    Wend                     'is used to contain all fetch data
End With                     'prior to reporting

StoreReportDetails       'Save all data on a daily basis and save to REPODETAILS table

StoreReportWeekSummary    'Summarizes data on a wkly basis and save REPOSUMMARY

Load dtaEnvPigs     'Environment using MSjet 4.0 OLE provider with SQL command:
                            '  SELECT  YearNr, monthnr, weeknr, tagnr, PigAge, pigtype,
                            '          feedcode, feedname,heads, eachmealkg, totalcost,
                            '          totalkg, bags FROM REPOSUMMARY

With dtaEnvPigs
     If .RepoSummary.State <> 0 Then
          dtaEnvPigs.RepoSummary.Close  'Close the environment after loading
    End If                                              'hoping the close,open procedure will[/COLOR]
End With                                              'update the datareport1[/COLOR]

If Not isSumReport Then                   'Two reports use this SUB    
    DataReport1.LeftMargin = 200
    DataReport1.ReportWidth = 8865
    DataReport1.Width = 9100

    DataReport1.Refresh
    If DataReport1.Visible = False Then DataReport1.Show 1

Else
    DataReport4.LeftMargin = 200
    DataReport4.ReportWidth = 8865
    DataReport4.Width = 9100

    DataReport4.Refresh
    If DataReport4.Visible = False Then DataReport4.Show

End If
Unload dtaEnvPigs
Me.MousePointer = vbNormal
dtaRepoSum.Refresh
End Sub

Rich, Thanks for your reply. I just tried it. Didn't work for me. I fetch a set of data records that could fill up to 7 columnar pages (e.g. feed requirements of a huge number of sows. very important for us farmers to forecast budgeting and raw materials). I think the size of the data being generated is pushing MS access or MS Jet4.0 provider to the limit. (not sure). I tried for the past few days to do all sorts of initializing the data environment, tables and data object but causing another error "failing to get row sets" (whatever). In the meantime, I am just contented with clicking the command button one more time as if refreshing the displayed report the 2nd time. Hey, that is what is available in Crystal Reports but unfortunately it's not available in my town as yet. At least, Im happy enough for now clicking my Ok button twice. Really appreciate your concern to newbies like me.

My bad, I have tried to cut and paste but I can't get the right formatting of my code on this message box.

After
.delete
try to put
.update

plusplus,

Thanks for the reply. It didn't work but I caught the idea that the data environment which somehow does the caching of data needs to be updated.

I have been fiddling with the data outside the application using MS Access/VB6 Addins - Visual Data Manager directly. And even reset my PC or manually deletes the records in the table being pointed by the data environment, still the old report data gets retained.

After few days of playing around with all the properties of the data environment, the BEGIN TRANS, COMMIT TRANS and putting a PAUSE using a MSGBOX did the work:

---------------------------------------------------------


'*** Save all data on a daily basis and save to REPODETAILS table
StoreReportDetails dStartDate, dEndDate

'Summarizes data on a weekly basis and save to a REPOSUMMARY table.
StoreReportWeekSummary
'*** Environment using MSjet 4.0 OLE provider with
' SQL command:
' SELECT YearNr, monthnr, weeknr, tagnr, PigAge, pigtype,
' feedcode, feedname,heads, eachmealkg, totalcost,
' totalkg, bags FROM REPOSUMMARY
'------------------------------------------------------

Load dtaEnvPigs


With dtaEnvPigs


'*** Open the dta environment, to prepare begintrans
If .RepoSummary.State = 0 Then .RepoSummary.Open
End If

'*** Force saving of data by committing transactions

dtaEnvPigs.RepoSummary.BeginTrans
dtaEnvPigs.RepoSummary.CommitTrans

'*** Close the environment after loading***
dtaEnvPigs.RepoSummary.Close

'*** Give the provider sufficient delay time to commit trans.
If MsgBox("Press Ok to continue.", vbOKCancel, "Options") = vbCancel Then Exit Sub
End If End With

'***Two reports use this SUB, if isSumReport is true, DataReport1 gets printed.***

If Not isSumReport Then
DataReport1.LeftMargin = 200
DataReport1.ReportWidth = 8865
DataReport1.Width = 9100
DataReport1.Title = IIf(isDiscounted, "Discounted", " ")

If DataReport1.Visible = False Then
DataReport1.Show 1
Else
DataReport4.LeftMargin = 200
DataReport4.ReportWidth = 8865
DataReport4.Width = 9100

If DataReport4.Visible = False Then DataReport4.ShowEnd If

'*** I don't need this trash anymore, unload it.
Unload dtaEnvPigs

Me.MousePointer = vbNormal
dtaRepoSum.Refresh
End Sub

To All good friends who replied and helped me, thanks a lot.

Qveen72 - God bless the queen. I hope
you found your rightful king.

Rich0001 - May you become richer.


plusplus - May you have more plus'es in your bank account.

God bless you all.

Just ran across your post looking for help on something similar.

Have you cleared the 'save old data with report' box on the report file itself?

Open the report, under File // Report Options
there will be a checkbox for "Save Data With Report". If it is checked, uncheck it and see if that fixes the issue.

Thansk
klheitz

Dim obj As New DataEnvironment1    'create object of DataEnvironment1
Set obj = New DataEnvironment1     'set
obj.Command1                       'execute command
Set DataReport1.DataSource = obj    'set datareport's datasource
DataReport1.Show

It retrive the updated database
reply me on [email removed]
:icon_razz: NjoY

commented: why you need to post on a thread which is already marked as solved as is more than 3 years old. -2

Dim obj As New DataEnvironment1 'create object of DataEnvironment1
Set obj = New DataEnvironment1 'set
obj.Command1 'execute command
Set DataReport1.DataSource = obj 'set datareport's datasource
DataReport1.Show

THIS CODE RETRIEVE UPDATED DATABASE
Enjoy!!!!!!!!! :icon_smile:

Hello everyone. I need help for refreshing report please... I already tried all suggestions but didn't work..please reply.. thanx.

hmmm....try u i.unload ang datareport... pero not your main form... solve na problem u po.... visit my website nlng for compliments... www.hamsori.weebly.com :)

Dim obj As New DataEnvironment1 'create object of DataEnvironment1
Set obj = New DataEnvironment1 'set
obj.Command1 'execute command
Set DataReport1.DataSource = obj 'set datareport's datasource
DataReport1.Show

THANK YOU.
THIS CODE SOLVED MY PROBLEM.

Just another thought I find works great! Simple solution:

dataenvironment1.rstitle.open
moviereport.show
dataenvironment1.rstitle.close

"title" is a sql command defined in a connect in my dataenvironment. When used in this manner you must precede it with "rs". moviereport is a data report dependent on the "title" query. In effect you're opening and closing the query so that new information is recognized.

when i print a landscape report my program sayes (( report width is larger than paper width )) how can i select type of paper and position of it in vb6 please

when i print a landscape report my program sayes (( report width is larger than paper width )) how can i select type of paper and position of it in vb6 please
plz anser me becausei can not find the anser
best reg.
kareem

please i use crystal report with vb6 ,i want same report dispaly twice in one paper , i mean twice invoice for same report but vertical report in one paper
one invoice to custom and another invoice to me.
i am from iraq please help me.
my email :mhmd_hanoon@yahoo.com

What is your project about?And what do you actually want to show on te Data Report. It is an easy task. No need to write too much of codes like this to create a repaort. If you write the SQL statement correctly inside the Dataenvironment as per the requirement and under the Button click you have to write about five to six lines to generate the report.

I have encountered such problem before but I solved it by trying some ideas. You can make a comment in my fb accts and I will give you the code. junlan438@yahoo.com

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.