Programmatically Referencing a Report

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Greetings,

I have a very "novice" question in regards to reports. I am trying to hide
several labels on a report base upon choices on the data entry form. The
current code I have is below:

If Me.ChecHomeImp.Value = 1 Then
[rptSurveyResults].lblHomeImprovementLoans.Visible = True
Else
[rptSurveyResults].lblBuyingaVacationHome.Visible = False
End If

However, when I run this code I receive an error stating that it can't find
the field, "|" indicated in my expression. Am I not referencing the report
properly?
 
I used the code below (with no errors), but it is still not displaying the
label on the
report if the approrpriate checkbox on the form has been checked. Is it not
possible to set the visible property of a label (on a report) at run time?
My goal is to have the report only display the labels that pertain to
checkboxes (that have been checked) on the main form. Am I approaching this
wrong?

[Note: I am running the code below from the "Click" event of a button on
the Data Entry form].

If Me.ChecHomeImp.Value = -1 Then
Reports![rptSurveyResults].lblHomeImprovementLoans.Visible = True
Else
Reports![rptSurveyResults].lblHomeImprovementLoans.Visible = False
End If

--
Thanks!

Sherwood


Roger Carlson said:
You are not referencing the report correctly. Either of these should work:
Reports![rptSurveyResults].lblHomeImprovementLoans.Visible = True
or
Me.lblHomeImprovementLoans.Visible = True

--
--Roger Carlson
Access Database Samples: www.rogersaccesslibrary.com
Want answers to your Access questions in your Email?
Free subscription:
http://peach.ease.lsoft.com/scripts/wa.exe?SUBED1=ACCESS-L


Sherwood said:
Greetings,

I have a very "novice" question in regards to reports. I am trying to hide
several labels on a report base upon choices on the data entry form. The
current code I have is below:

If Me.ChecHomeImp.Value = 1 Then
[rptSurveyResults].lblHomeImprovementLoans.Visible = True
Else
[rptSurveyResults].lblBuyingaVacationHome.Visible = False
End If

However, when I run this code I receive an error stating that it can't find
the field, "|" indicated in my expression. Am I not referencing the report
properly?
 
Sherwood said:
I have a very "novice" question in regards to reports. I am trying to hide
several labels on a report base upon choices on the data entry form. The
current code I have is below:

If Me.ChecHomeImp.Value = 1 Then
[rptSurveyResults].lblHomeImprovementLoans.Visible = True
Else
[rptSurveyResults].lblBuyingaVacationHome.Visible = False
End If

However, when I run this code I receive an error stating that it can't find
the field, "|" indicated in my expression. Am I not referencing the report
properly?


You can not reliably manipulate a report from outside the
report because the form is not synchronized with the report
opening and displaying.

This kind of thing should be done in the report, probably in
its Open event:

If Forms!yourform.ChecHomeImp = 1 Then
Me.lblHomeImprovementLoans.Visible = True
Else
Me.lblBuyingaVacationHome.Visible = False
End If
 
I have tried the syntax you mentioned (in the "Open" event of the report),
but it is not working. I am not receiving an error, it just isn't making the
label visible on the report if the checkbox is selected on the form. Also,
as I typed in the line of code below, "Visible" is not one of the listed
properties that displays (even though I have Auto List Members checked under
"Tools, Options, Editor"). Any ideas? [Note: I have to use "-1" to see if
a checkbox has been selected instead of "1"].

Private Sub Report_Open(Cancel As Integer)
If Forms![frmMainSurvey].ChecHomeImp.Value = -1 Then
Me.lblHomeImprovementLoans.Visible = True
Else
Reports![rptSurveyResults].lblHomeImprovementLoans.Visible = False
Me.lblHomeImprovementLoans.Visible = False
End If
--
Thanks!

Sherwood


Marshall Barton said:
Sherwood said:
I have a very "novice" question in regards to reports. I am trying to hide
several labels on a report base upon choices on the data entry form. The
current code I have is below:

If Me.ChecHomeImp.Value = 1 Then
[rptSurveyResults].lblHomeImprovementLoans.Visible = True
Else
[rptSurveyResults].lblBuyingaVacationHome.Visible = False
End If

However, when I run this code I receive an error stating that it can't find
the field, "|" indicated in my expression. Am I not referencing the report
properly?


You can not reliably manipulate a report from outside the
report because the form is not synchronized with the report
opening and displaying.

This kind of thing should be done in the report, probably in
its Open event:

If Forms!yourform.ChecHomeImp = 1 Then
Me.lblHomeImprovementLoans.Visible = True
Else
Me.lblBuyingaVacationHome.Visible = False
End If
 
Try it in the On Format event of the Detail Section.

--
--Roger Carlson
Access Database Samples: www.rogersaccesslibrary.com
Want answers to your Access questions in your Email?
Free subscription:
http://peach.ease.lsoft.com/scripts/wa.exe?SUBED1=ACCESS-L


Sherwood said:
I have tried the syntax you mentioned (in the "Open" event of the report),
but it is not working. I am not receiving an error, it just isn't making the
label visible on the report if the checkbox is selected on the form. Also,
as I typed in the line of code below, "Visible" is not one of the listed
properties that displays (even though I have Auto List Members checked under
"Tools, Options, Editor"). Any ideas? [Note: I have to use "-1" to see if
a checkbox has been selected instead of "1"].

Private Sub Report_Open(Cancel As Integer)
If Forms![frmMainSurvey].ChecHomeImp.Value = -1 Then
Me.lblHomeImprovementLoans.Visible = True
Else
Reports![rptSurveyResults].lblHomeImprovementLoans.Visible = False
Me.lblHomeImprovementLoans.Visible = False
End If
--
Thanks!

Sherwood


Marshall Barton said:
Sherwood said:
I have a very "novice" question in regards to reports. I am trying to hide
several labels on a report base upon choices on the data entry form. The
current code I have is below:

If Me.ChecHomeImp.Value = 1 Then
[rptSurveyResults].lblHomeImprovementLoans.Visible = True
Else
[rptSurveyResults].lblBuyingaVacationHome.Visible = False
End If

However, when I run this code I receive an error stating that it can't find
the field, "|" indicated in my expression. Am I not referencing the report
properly?


You can not reliably manipulate a report from outside the
report because the form is not synchronized with the report
opening and displaying.

This kind of thing should be done in the report, probably in
its Open event:

If Forms!yourform.ChecHomeImp = 1 Then
Me.lblHomeImprovementLoans.Visible = True
Else
Me.lblBuyingaVacationHome.Visible = False
End If
 
Sherwood said:
I have tried the syntax you mentioned (in the "Open" event of the report),
but it is not working. I am not receiving an error, it just isn't making the
label visible on the report if the checkbox is selected on the form. Also,
as I typed in the line of code below, "Visible" is not one of the listed
properties that displays (even though I have Auto List Members checked under
"Tools, Options, Editor"). Any ideas? [Note: I have to use "-1" to see if
a checkbox has been selected instead of "1"].

Private Sub Report_Open(Cancel As Integer)
If Forms![frmMainSurvey].ChecHomeImp.Value = -1 Then
Me.lblHomeImprovementLoans.Visible = True
Else
Reports![rptSurveyResults].lblHomeImprovementLoans.Visible = False
Me.lblHomeImprovementLoans.Visible = False
End If


I don't see how that can happen when the form checkbox is
checked unless there is something else wrong. Although I
would expect some kind of error if these are not right, make
sure the form is still open and that the names of everything
are spelled correctly.

It looks like you have an extra line in the Else situation
or maybe you're just using the long reference??? This line
is not wrong, but would normally be written:

Me.lblHomeImprovementLoans.Visible = False
 
Try this:

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)

If Me.ChecHomeImp= yes Then
Me.lblHomeImprovementLoans.Visible = True
Else
Me.lblHomeImprovementLoans.Visible = False

you may need to change yes to -1 since its a text box.





Sherwood said:
I have tried the syntax you mentioned (in the "Open" event of the report),
but it is not working. I am not receiving an error, it just isn't making the
label visible on the report if the checkbox is selected on the form. Also,
as I typed in the line of code below, "Visible" is not one of the listed
properties that displays (even though I have Auto List Members checked under
"Tools, Options, Editor"). Any ideas? [Note: I have to use "-1" to see if
a checkbox has been selected instead of "1"].

Private Sub Report_Open(Cancel As Integer)
If Forms![frmMainSurvey].ChecHomeImp.Value = -1 Then
Me.lblHomeImprovementLoans.Visible = True
Else
Reports![rptSurveyResults].lblHomeImprovementLoans.Visible = False
Me.lblHomeImprovementLoans.Visible = False
End If
--
Thanks!

Sherwood


Marshall Barton said:
Sherwood said:
I have a very "novice" question in regards to reports. I am trying to hide
several labels on a report base upon choices on the data entry form. The
current code I have is below:

If Me.ChecHomeImp.Value = 1 Then
[rptSurveyResults].lblHomeImprovementLoans.Visible = True
Else
[rptSurveyResults].lblBuyingaVacationHome.Visible = False
End If

However, when I run this code I receive an error stating that it can't find
the field, "|" indicated in my expression. Am I not referencing the report
properly?


You can not reliably manipulate a report from outside the
report because the form is not synchronized with the report
opening and displaying.

This kind of thing should be done in the report, probably in
its Open event:

If Forms!yourform.ChecHomeImp = 1 Then
Me.lblHomeImprovementLoans.Visible = True
Else
Me.lblBuyingaVacationHome.Visible = False
End If
 
Back
Top