Code that works but doesn't work

mcdhappy80

Registered User.
Local time
Today, 06:20
Joined
Jun 22, 2009
Messages
347
Code loads value in Preview, but value doesn't print

I have a master report which I open. On that report there are 4 sub reports.
In OnLoad event of a master report there is this code:
Code:
Private Sub Report_Load()

'Punjenje polja txtCasovaNedeljno
Dim casDn As Integer
Dim casNe As Integer
casDn = CInt(Me.subRepUgovorORadu1.Report![txtCasovaDnevno])
casNe = casDn * 5
Me.subRepUgovorORadu1.Report![txtCasovaNedeljno] = CStr(casNe)

'Punjenje polja txtDirektor
On Error GoTo Poruka
    Dim rs As DAO.Recordset
    Dim direktor As String
    Dim strSql As String
    strSql = "SELECT [tblZaposleni].[txtIme] & ' ' & [tblZaposleni].[txtPrezime] As Direktor " _
       & "FROM tblPoslovi INNER JOIN tblZaposleni ON tblPoslovi.intPosaoID = tblZaposleni.intPosloviID " _
       & "WHERE intPosloviID = 1;"
    Set rs = CurrentDb.OpenRecordset(strSql)
    direktor = rs.Fields("Direktor").Value
    rs.Close
    Set rs = Nothing
    Me.subRepUgovorORadu4.Report![txtDirektor] = direktor
Exit Sub

Poruka:
    Me.subRepUgovorORadu4.Report![txtDirektor] = "Unesite direktora"
    
End Sub
So basically this code fills two text field controls with data.
The master report opens a form and this code is assigned to button on form:
Code:
Private Sub btnRepUgovorORaduFinal_Click()
DoCmd.OpenReport "repUgovorORaduFinal", acViewPreview, "qryUgovor_frmPregledUgovor", "[qryUgovor_frmPregledUgovor]![intUgovorID]=" & [Forms]![frmUgovorPregled]![intUgovorID]
DoCmd.PrintOut acSelection, , , acHigh,4
End Sub
The problem is this.
When i open master form in Normal mode the required data for the two fields is there. When I preview it in print mode it isn't there.
The reason I'm opening this report in Print Preview mode is it doesn't look good in Normal preview mode. Some of the labels and text fields on sub reports don't display as they should.
Why is this?
How do I fix it?
Thank You.
 
Last edited:
I would suggest putting in a 'docmd.requery' just before you open the report.
 
Re: Code loads value in Preview, but value doesn't print

I would suggest putting in a 'docmd.requery' just before you open the report.

I tried requery method but it doesn't work.

This problem is confusing because I have other form in same database, which consist of only one A4 page. That report has the same code in its OnLoad event:
Code:
Private Sub Report_Load()
On Error GoTo Poruka
    Dim rs As DAO.Recordset
    Dim direktor As String
    Dim strSql As String
    strSql = "SELECT [tblZaposleni].[txtIme] & ' ' & [tblZaposleni].[txtPrezime] As Direktor " _
        & "FROM tblPoslovi INNER JOIN tblZaposleni ON tblPoslovi.intPosaoID = tblZaposleni.intPosloviID " _
        & "WHERE intPosloviID = 1;"
    Set rs = CurrentDb.OpenRecordset(strSql)
    direktor = rs.Fields("Direktor").Value
    rs.Close
    Set rs = Nothing
    Me.txtDirektor = direktor
Exit Sub

Poruka:
    Me.txtDirektor = "Unesite direktora"
End Sub
This report is opened from a form also, the button that opens it has this code attached to it:
Code:
DoCmd.OpenReport "repResenje1", acViewReport, "qryZaposleni", "[qryZaposleni]![intZaposleniID]=" & [Forms]![frmZaposleniPregled]![intZaposleniID]
This form also has print button in its header. The code for print is this:
Code:
Private Sub btnStampaj_Click()

On Error GoTo Poruka

Stampa:
    DoCmd.PrintOut acSelection, , , acHigh 'Ubaciti broj stranica = 3
    DoCmd.Close acReport, "repResenje1", acSaveNo
Exit Sub

Poruka:
    MsgBox "Morate prikljuciti stampac!"
End Sub
And when I open this form, and click print, it prints nicely with all the data.
What I noticed is when I switch this form that prints nicely in Print Preview mode, the data that loads in OnLoad event is gone.

So, the only difference between the form that prints as it should and the form that doesn't is:
1) The form that prints opens itself in acViewReport mode and the one that doesn't opens itself in acViewPreview.
2) The form that prints itself nicely is one page long, the form that doesn't is four A4 pages long, and to achieve that 4 pages effect it consists of 4 subReports (which are separate reports) because the maximum height of detail area on report is 25" and 4 pages is more than 25" in height.
3) The other reason the form is in acViewPreview is because when I add sub reports they don't display well in AcViewReport.

Here are some screens with explanation:
1) On this picture You can see the form that prints nicely. The text highlighted in red is the text field unbound control that fills with text on load:
frm1final.jpg


2) On this picture You can see the second form that doesn't print nicely although, the data that is needed is there when the form opens. It opens in print preview and the data that fill OnLoad is number 40 on page one and Milan Cvetkovic text on page 2. But these two items do not print.
frm2_view1.jpg


3) On this picture is the same form (the one that doesn't print) only in acViewReport . On page 1 you can see overlaping of sub Reports (even if they are put one below other in forms Design view.
frm2_view2.jpg


Hope this explains a little bit, and that someone can help me.
Thank You.
 
Last edited:
Code loads value in Preview, but value doesn't print

I've experimented little more with this. When the form opens in Preview mode the value is there (see picture):

repPreview.jpg


When I click print, the value doesn't print. What am I doing wrong here?

Thank You.
 
Ive got to say ive never had that happen before. All I can sugges tis make sure that all the properties of the boxes that arent showing are ok (i.e. visible, with contrasting back and fore colours)
Hope you get it sorted, sorry i can be of more help!
 
Ive got to say ive never had that happen before. All I can sugges tis make sure that all the properties of the boxes that arent showing are ok (i.e. visible, with contrasting back and fore colours)
Hope you get it sorted, sorry i can be of more help!
All the control fields are visible, and are to show all the time (on screen and when printing). The colors are all set to black.
As I said everything works fine on report one A4 page long, but doesn't work on 4 A4 pages long report (the one with four subreports).
I really don't know what to do. I guess I'll have to make different approach on solving this, but unfortunately that will involve, changing tables and everything, and storing the calculated values in fields and printing them that way.
 

Users who are viewing this thread

Back
Top Bottom