Change text in report based on dialog box

G

Guest

Hi,

I'm working with Access 2003.

I've been doing this in Word and Access and now want to use only Access. I
have a report that has renewal options. There are 3 reports that are
basically the same; except for one line.
Your membership is about to expire
Your membership has recently expired
Your membership is expired.

I had a dialog box that typed in the correct text into a word document. I'm
not sure how to approach this in access. How do I have vba create a text box
with the correct text and put in into the proper position in the report? I'm
assuming that it is the same to create the dialog box in access.

Thanks.

jbc
 
A

Allen Browne

Just put a text box on the report, and set its Control Source to something
like this:
=[Describe the reason to show in these letters]

When you run the report, Access will not be able to find any field by that
name (hopefully), so it will presume it is a parameter that the user should
supply at runtime.

There are probably nicer suggestions, such as an option group on a form
where the user can select from the 3 options, and the text box on the report
responds with the right text.
 
G

Guest

hi,

I would like to tie it into a dialog box with radio buttons. That's the way
I did it in word. I really don't want to type the text each time.

how do I get the variable into a text box and position it in the report?

thanks.

Jbc

Allen Browne said:
Just put a text box on the report, and set its Control Source to something
like this:
=[Describe the reason to show in these letters]

When you run the report, Access will not be able to find any field by that
name (hopefully), so it will presume it is a parameter that the user should
supply at runtime.

There are probably nicer suggestions, such as an option group on a form
where the user can select from the 3 options, and the text box on the report
responds with the right text.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

jbc said:
Hi,

I'm working with Access 2003.

I've been doing this in Word and Access and now want to use only Access.
I
have a report that has renewal options. There are 3 reports that are
basically the same; except for one line.
Your membership is about to expire
Your membership has recently expired
Your membership is expired.

I had a dialog box that typed in the correct text into a word document.
I'm
not sure how to approach this in access. How do I have vba create a text
box
with the correct text and put in into the proper position in the report?
I'm
assuming that it is the same to create the dialog box in access.

Thanks.

jbc
 
A

Allen Browne

1. Create a form (not bound to any table).

2. Add the Option Group, with 3 buttons.
Name the group (say) grpLetter.
Set the Default Value of the group to 1 (or the most likely choice.)
Name the 3 buttons optLetter1, optLetter2, and optLetter3 respectively.
Set the attached label of each button to the text you want in your letter.

3. Add a command button.
Name it cmdOk.
Set its Caption to Ok.
Set its On Click property to: [Event Procedure]
Click the Build button (...) beside that.
Add this to the code window, replacing Report1 with the name of your report:
Private Sub cmdOk_Click()
Const strcDoc = "Report1"
If CurrentProject.AllReports(strcDoc).IsLoaded Then
DoCmd.Close acReport, strcDoc, asSaveYes
End If
DoCmd.OpenReport strcDoc, acViewPreview
End Sub

4. Save the form with the name fdlgLetter. Close.

5. Open the report in design view.
Remove the text box suggested last post.
Add a label named lblLetter.
Set its Width so it copes with the widest text, and clear its Caption.

6. Add something like this to the Open event procedure of your report:

Private Sub Report_Open(Cancel As Integer)
Dim strButtonName As String
If CurrentProject.AllForms("fdlgLetter").IsLoaded Then
Me.lblLetterDescrip.Caption
With Forms("fdlgLetter")
strButtonName = "optLetter" & .grpLetter.Value
Me.lblLetter.Caption =
..Controls(strButtonName).Controls(0).Caption
End With
Else
MsgBox "Open this report through the form fdlgLetter"
Cancel = True
End If
End Sub

The idea is that you open the form, choose the letter type, and click the Ok
button to open the report. The report then looks at which option group is
chosen on the form, reads the text from the Caption of the Label attached to
the option button of the chosen value in the option group, and puts it into
the Caption of the label on the report.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

jbc said:
I would like to tie it into a dialog box with radio buttons. That's the
way
I did it in word. I really don't want to type the text each time.

how do I get the variable into a text box and position it in the report?

thanks.

Jbc

Allen Browne said:
Just put a text box on the report, and set its Control Source to
something
like this:
=[Describe the reason to show in these letters]

When you run the report, Access will not be able to find any field by
that
name (hopefully), so it will presume it is a parameter that the user
should
supply at runtime.

There are probably nicer suggestions, such as an option group on a form
where the user can select from the 3 options, and the text box on the
report
responds with the right text.

jbc said:
I'm working with Access 2003.

I've been doing this in Word and Access and now want to use only
Access.
I
have a report that has renewal options. There are 3 reports that are
basically the same; except for one line.
Your membership is about to expire
Your membership has recently expired
Your membership is expired.

I had a dialog box that typed in the correct text into a word document.
I'm
not sure how to approach this in access. How do I have vba create a
text
box
with the correct text and put in into the proper position in the
report?
I'm
assuming that it is the same to create the dialog box in access.
 
G

Guest

Allen,

Thank you for your time and advice. I'll have to try it out.

Thanks again.

jbc

Allen Browne said:
1. Create a form (not bound to any table).

2. Add the Option Group, with 3 buttons.
Name the group (say) grpLetter.
Set the Default Value of the group to 1 (or the most likely choice.)
Name the 3 buttons optLetter1, optLetter2, and optLetter3 respectively.
Set the attached label of each button to the text you want in your letter.

3. Add a command button.
Name it cmdOk.
Set its Caption to Ok.
Set its On Click property to: [Event Procedure]
Click the Build button (...) beside that.
Add this to the code window, replacing Report1 with the name of your report:
Private Sub cmdOk_Click()
Const strcDoc = "Report1"
If CurrentProject.AllReports(strcDoc).IsLoaded Then
DoCmd.Close acReport, strcDoc, asSaveYes
End If
DoCmd.OpenReport strcDoc, acViewPreview
End Sub

4. Save the form with the name fdlgLetter. Close.

5. Open the report in design view.
Remove the text box suggested last post.
Add a label named lblLetter.
Set its Width so it copes with the widest text, and clear its Caption.

6. Add something like this to the Open event procedure of your report:

Private Sub Report_Open(Cancel As Integer)
Dim strButtonName As String
If CurrentProject.AllForms("fdlgLetter").IsLoaded Then
Me.lblLetterDescrip.Caption
With Forms("fdlgLetter")
strButtonName = "optLetter" & .grpLetter.Value
Me.lblLetter.Caption =
..Controls(strButtonName).Controls(0).Caption
End With
Else
MsgBox "Open this report through the form fdlgLetter"
Cancel = True
End If
End Sub

The idea is that you open the form, choose the letter type, and click the Ok
button to open the report. The report then looks at which option group is
chosen on the form, reads the text from the Caption of the Label attached to
the option button of the chosen value in the option group, and puts it into
the Caption of the label on the report.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

jbc said:
I would like to tie it into a dialog box with radio buttons. That's the
way
I did it in word. I really don't want to type the text each time.

how do I get the variable into a text box and position it in the report?

thanks.

Jbc

Allen Browne said:
Just put a text box on the report, and set its Control Source to
something
like this:
=[Describe the reason to show in these letters]

When you run the report, Access will not be able to find any field by
that
name (hopefully), so it will presume it is a parameter that the user
should
supply at runtime.

There are probably nicer suggestions, such as an option group on a form
where the user can select from the 3 options, and the text box on the
report
responds with the right text.


I'm working with Access 2003.

I've been doing this in Word and Access and now want to use only
Access.
I
have a report that has renewal options. There are 3 reports that are
basically the same; except for one line.
Your membership is about to expire
Your membership has recently expired
Your membership is expired.

I had a dialog box that typed in the correct text into a word document.
I'm
not sure how to approach this in access. How do I have vba create a
text
box
with the correct text and put in into the proper position in the
report?
I'm
assuming that it is the same to create the dialog box in access.
 

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