VBA - Easy Question

M

MVP - WannaB

I am trying to populate the value of an unbound text filed on a report, but I
am doing somethign a little wrong, because it doesn't recognize the name of
the text field.. Here is my code, I'm msure someone here will post this it
is so simple, but not for me - today..
Select Case Me.Frm_ReportFilter.Value
Case 1
stFilter = "[DB Change Log].priority ='0'"
[rDB Change Log- Priority 0].text45 = "Priority = 0"
Case 2
stFilter = "([DB Change Log].priority <>'0' OR [DB Change
Log].priority is null) and [DB Change Log].completed is null"
[rDB Change Log- Priority 0].text45 = "Priority <> 0"
End Select
Thanks you, I really appreciate your help !!!!
 
T

Tom Wickerath

It's not real clear to me where your Select Case....End Select code is found.
Is it in a form's class module? If so, try setting an unbound text box to
whatever string you want. This text box will have it's visible property set
to No, so that it is not displayed on the form. For example:

Me.txtFilter = "Priority = 0"

Then, in the report's text box (presumably "text45", based on your
example--please do give this text box a more reasonable name), you set an
expression to point to the open form. For example:

= [Forms]![Frm_ReportFilter]![txtFilter]

Of course, the Frm_ReportFilter form must be open, and the txtFilter text
box should have a value stuffed into it, by the time your report starts to
open.


Tom Wickerath
Microsoft Access MVP
http://www.accessmvp.com/TWickerath/
http://www.access.qbuilt.com/html/expert_contributors.html
__________________________________________
 
M

MVP - WannaB

Thanks very much, Tom.
First I am so sorry that I was so stupid as to post only the case statement.
This is a private sub button click, form class module and all the code is
posted at the end of my comments.
I think what you are saying is that when calling the report from a class
module, I am not yet able to change the value of an unbound field on a report
that is not yet open ??? So by setting the value on a form field that is
read from the report that will solve this. Am I correct, or close maybe??
Now here is my new thought, I already have 2 fields on the form that pretty
much contain what I want printed in the report. I'll try to explain this
clearly, but no guarantees. On the Form I have a group option, in the group
option I have 3 options, and each option has a label. The option box is used
to select the parameters for one report or select a different report. If I
can use the caption of the option label as the value in text45, that would
solve everything. And, Yes I will rename text45 to something more
descriptive once I get everything working.
I've got this working but if there's way that I could have used the option
labels better, please let me know.

Private Sub cmd_Prv_RPT_Click()
On Error GoTo Err_cmd_Prv_RPT_Click

Dim stDocName, stFilter As String

Select Case Me.Opt_ReportFilter.Value
Case 1
stDocName = "r_DB Change Log"
stFilter = "[DB Change Log].priority ='0'"
Me.[RptLbl_Source] = Me.Label82.Caption
Case 2
stDocName = "r_DB Change Log"
stFilter = "([DB Change Log].priority <>'0' OR [DB Change
Log].priority is null) and [DB Change Log].completed is null"
Me.[RptLbl_Source] = Me.Label84.Caption
Case 3
stDocName = "r_DB Change Log - Implemented"
stFilter = ""
Me.[RptLbl_Source] = Me.Label86.Caption
End Select

DoCmd.OpenReport stDocName, acPreview, , stFilter

Exit_cmd_Prv_RPT_Click:
Exit Sub
======================================
Tom Wickerath said:
It's not real clear to me where your Select Case....End Select code is found.
Is it in a form's class module? If so, try setting an unbound text box to
whatever string you want. This text box will have it's visible property set
to No, so that it is not displayed on the form. For example:

Me.txtFilter = "Priority = 0"

Then, in the report's text box (presumably "text45", based on your
example--please do give this text box a more reasonable name), you set an
expression to point to the open form. For example:

= [Forms]![Frm_ReportFilter]![txtFilter]

Of course, the Frm_ReportFilter form must be open, and the txtFilter text
box should have a value stuffed into it, by the time your report starts to
open.


Tom Wickerath
Microsoft Access MVP
http://www.accessmvp.com/TWickerath/
http://www.access.qbuilt.com/html/expert_contributors.html
__________________________________________

MVP - WannaB said:
I am trying to populate the value of an unbound text filed on a report, but I
am doing somethign a little wrong, because it doesn't recognize the name of
the text field.. Here is my code, I'm msure someone here will post this it
is so simple, but not for me - today..
Select Case Me.Frm_ReportFilter.Value
Case 1
stFilter = "[DB Change Log].priority ='0'"
[rDB Change Log- Priority 0].text45 = "Priority = 0"
Case 2
stFilter = "([DB Change Log].priority <>'0' OR [DB Change
Log].priority is null) and [DB Change Log].completed is null"
[rDB Change Log- Priority 0].text45 = "Priority <> 0"
End Select
Thanks you, I really appreciate your help !!!!
 
T

Tom Wickerath

I think what you are saying is that when calling the report from a class
module, I am not yet able to change the value of an unbound field on a report
that is not yet open ???

Rather than try to "push" the value to the report, let the report "pull" the
value from your open form.
So by setting the value on a form field that is read from the report that
will solve this. Am I correct, or close maybe??

Correct. Try this sample, which is fairly elementary, but it does
demonstrate the point:

http://www.accessmvp.com/TWickerath/downloads/customdialogbox.zip

Select a date range for an order, that is within the earliest and latest
dates indicated, ie. between 15Jun1994 and 25Jun2006. When you run the
report, you should see the dates you selected displayed in a bound text box.
In this case, the text box is bound to an expression (not a field) that gets
it's value from the open form. (The form is opened in hidden mode when you
click on the OK button, so it's still open, but you just cannot see it).

Does this help?


Tom Wickerath
Microsoft Access MVP
http://www.accessmvp.com/TWickerath/
http://www.access.qbuilt.com/html/expert_contributors.html
__________________________________________

MVP - WannaB said:
Thanks very much, Tom.
First I am so sorry that I was so stupid as to post only the case statement.
This is a private sub button click, form class module and all the code is
posted at the end of my comments.
I think what you are saying is that when calling the report from a class
module, I am not yet able to change the value of an unbound field on a report
that is not yet open ??? So by setting the value on a form field that is
read from the report that will solve this. Am I correct, or close maybe??
Now here is my new thought, I already have 2 fields on the form that pretty
much contain what I want printed in the report. I'll try to explain this
clearly, but no guarantees. On the Form I have a group option, in the group
option I have 3 options, and each option has a label. The option box is used
to select the parameters for one report or select a different report. If I
can use the caption of the option label as the value in text45, that would
solve everything. And, Yes I will rename text45 to something more
descriptive once I get everything working.
I've got this working but if there's way that I could have used the option
labels better, please let me know.

Private Sub cmd_Prv_RPT_Click()
On Error GoTo Err_cmd_Prv_RPT_Click

Dim stDocName, stFilter As String

Select Case Me.Opt_ReportFilter.Value
Case 1
stDocName = "r_DB Change Log"
stFilter = "[DB Change Log].priority ='0'"
Me.[RptLbl_Source] = Me.Label82.Caption
Case 2
stDocName = "r_DB Change Log"
stFilter = "([DB Change Log].priority <>'0' OR [DB Change
Log].priority is null) and [DB Change Log].completed is null"
Me.[RptLbl_Source] = Me.Label84.Caption
Case 3
stDocName = "r_DB Change Log - Implemented"
stFilter = ""
Me.[RptLbl_Source] = Me.Label86.Caption
End Select

DoCmd.OpenReport stDocName, acPreview, , stFilter

Exit_cmd_Prv_RPT_Click:
Exit Sub
 
M

MVP - WannaB

WOW, that's nice. Very Helpful, thanks Tom.
I've only done a quick review, looking at all that is behind the forms, and
I know I can learn a lot from this. That Calendar form should be real nice.
I'm assuming this works like the (I think it's an activeX that needs to be
loaded via references "MSCAL.Calendar.7", but this would not need that
referrence).

But back to my question regarding the code at the bottom here " I've got
this working but if there's way that I could have used the option labels
better, please let me know."; ARE YOU SAYING THAT it would be better if I
created a form like those in your example?
===================================
Tom Wickerath said:
I think what you are saying is that when calling the report from a class
module, I am not yet able to change the value of an unbound field on a report
that is not yet open ???

Rather than try to "push" the value to the report, let the report "pull" the
value from your open form.
So by setting the value on a form field that is read from the report that
will solve this. Am I correct, or close maybe??

Correct. Try this sample, which is fairly elementary, but it does
demonstrate the point:

http://www.accessmvp.com/TWickerath/downloads/customdialogbox.zip

Select a date range for an order, that is within the earliest and latest
dates indicated, ie. between 15Jun1994 and 25Jun2006. When you run the
report, you should see the dates you selected displayed in a bound text box.
In this case, the text box is bound to an expression (not a field) that gets
it's value from the open form. (The form is opened in hidden mode when you
click on the OK button, so it's still open, but you just cannot see it).

Does this help?


Tom Wickerath
Microsoft Access MVP
http://www.accessmvp.com/TWickerath/
http://www.access.qbuilt.com/html/expert_contributors.html
__________________________________________

MVP - WannaB said:
Thanks very much, Tom.
First I am so sorry that I was so stupid as to post only the case statement.
This is a private sub button click, form class module and all the code is
posted at the end of my comments.
I think what you are saying is that when calling the report from a class
module, I am not yet able to change the value of an unbound field on a report
that is not yet open ??? So by setting the value on a form field that is
read from the report that will solve this. Am I correct, or close maybe??
Now here is my new thought, I already have 2 fields on the form that pretty
much contain what I want printed in the report. I'll try to explain this
clearly, but no guarantees. On the Form I have a group option, in the group
option I have 3 options, and each option has a label. The option box is used
to select the parameters for one report or select a different report. If I
can use the caption of the option label as the value in text45, that would
solve everything. And, Yes I will rename text45 to something more
descriptive once I get everything working.
I've got this working but if there's way that I could have used the option
labels better, please let me know.

Private Sub cmd_Prv_RPT_Click()
On Error GoTo Err_cmd_Prv_RPT_Click

Dim stDocName, stFilter As String

Select Case Me.Opt_ReportFilter.Value
Case 1
stDocName = "r_DB Change Log"
stFilter = "[DB Change Log].priority ='0'"
Me.[RptLbl_Source] = Me.Label82.Caption
Case 2
stDocName = "r_DB Change Log"
stFilter = "([DB Change Log].priority <>'0' OR [DB Change
Log].priority is null) and [DB Change Log].completed is null"
Me.[RptLbl_Source] = Me.Label84.Caption
Case 3
stDocName = "r_DB Change Log - Implemented"
stFilter = ""
Me.[RptLbl_Source] = Me.Label86.Caption
End Select

DoCmd.OpenReport stDocName, acPreview, , stFilter

Exit_cmd_Prv_RPT_Click:
Exit Sub
 
T

Tom Wickerath

The calendar form is Access MVP Allen Browne's sample. It is not an ActiveX
control, so you won't have registration headaches with it, as you might with
the Microsoft ActiveX Calendar control. Here is Allen's page that discusses
this calendar:

http://allenbrowne.com/ser-51.html
But back to my question regarding the code at the bottom here " I've got
this working but if there's way that I could have used the option labels
better, please let me know.";

I'm not sure what you are asking here....
In general, I would have the report pull data, as needed, instead of trying
to push data to the report.
ARE YOU SAYING THAT it would be better if I
created a form like those in your example?

Would you like my biased opinion? <smile>
Yes.


Tom Wickerath
Microsoft Access MVP
http://www.accessmvp.com/TWickerath/
http://www.access.qbuilt.com/html/expert_contributors.html
__________________________________________
 
M

MVP - WannaB

Sorry I am not making myself clear.
I think you have already answered the question with the sample that I
retrieved from your link. After a deeper study of that sample I see that
what I have done is very much like the selection on the sample form that
provide the user with option to select if they want to view a query, preview
a report, ....
I will try to keep in mind the idea of pulling data into object rather then
attempting to push it to the object.
AND YES, biased or unbiased I am alway willing to hear opinions.
EVERBODY HAS ONE, they are often different and when you put them all
together stir them up and normalize, sometimes one can come to a new
understanding of things.
Thanks again Tom, I look forward to reponses from you to future questions.
================================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top