Control source prob????????

K

KRISH

Hi! Everybody, Please help me........

I want to give user to design a letters of his own. For
which I design a form which stores the value of control
source of the report in a table. like para1, para2, etc.
value of para1 is like "<some text> & [First Name] & <some
text>". The text ofcourse in quotation marks. Now I would
like to place a textbox, whose control source should be
the value of para1. I tried like the below

I am assigning [Para1] as control source to
an unbound text box in my report say [Text1]. When I open
the report it is showing the code as stored in the table
field [Para1]. But actually I want in the output [field1]
should be replaced with the value of the field. kindly
help. Thanks for any help.

krish
 
A

Allen Browne

In Access 2000 and later, you can use the Replace() function to replace the
text in the memo field with the value from the field.

For example, if your memo field contains:
Thank you, <firstname>, for your donation
then on your report, you would use a text box with ControlSource of:
=Replace([MyMemo], "<firstname>", [First Name])

Make sure the Name of this text box is not the same as the name of a field:
that causes an error in Access.

If you have lots of these replacements to make, it is probably easiest to
write a function that opens the table of replacements and loops through all
those records to perform each replacement, returning the resultant string.
 
K

KRISH

Thanks but I think you could not get my problem.

I have created a Table1 with field [Para1]. Now I am
storing a value in [Para1] like,

"Thank you, " & [First Name] & " for your donation"

[First Name] is the field of another tabel say [Customer].

In the report I am placing a unbound text box and set its
control source to say [Para1]. Now my problem is if I open
the report it is showing the value of unbound text box as
below:

"Thank you, " & [First Name] & " for your donation"

But actually I want [First Name] should be replaced by the
name of the customer.

Hope you understand my problem. kindly help how to solve
it. Thanks for any help.

krish

-----Original Message-----
In Access 2000 and later, you can use the Replace() function to replace the
text in the memo field with the value from the field.

For example, if your memo field contains:
Thank you, <firstname>, for your donation
then on your report, you would use a text box with ControlSource of:
=Replace([MyMemo], "<firstname>", [First Name])

Make sure the Name of this text box is not the same as the name of a field:
that causes an error in Access.

If you have lots of these replacements to make, it is probably easiest to
write a function that opens the table of replacements and loops through all
those records to perform each replacement, returning the resultant string.

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

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

Hi! Everybody, Please help me........

I want to give user to design a letters of his own. For
which I design a form which stores the value of control
source of the report in a table. like para1, para2, etc.
value of para1 is like "<some text> & [First Name] & <some
text>". The text ofcourse in quotation marks. Now I would
like to place a textbox, whose control source should be
the value of para1. I tried like the below

I am assigning [Para1] as control source to
an unbound text box in my report say [Text1]. When I open
the report it is showing the code as stored in the table
field [Para1]. But actually I want in the output [field1]
should be replaced with the value of the field. kindly
help. Thanks for any help.

krish


.
 
A

Allen Browne

Krish, to do that you would need to use an unbound text box. Then in the
Format event of the section that contains this text box, lookup the values
in the table, and assign the result to the Control Source of your text box,
with an Equal sign at the start.

Something like this:

Private Sub Detail_Format(...
Dim varResult as String
varResult = DLookup("Para1", "Table1")
If IsNull(varResult) Then
Me.MyTextbox.ControlSource = vbnullstring
Else
Me.MyTextbbox.ControlSource = "=" & varResult
End If
End Sub

My guess is that it would be more efficient to place a token in the para1
field, and use Replace() rather than reassign the text box for each record.

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

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

KRISH said:
Thanks but I think you could not get my problem.

I have created a Table1 with field [Para1]. Now I am
storing a value in [Para1] like,

"Thank you, " & [First Name] & " for your donation"

[First Name] is the field of another tabel say [Customer].

In the report I am placing a unbound text box and set its
control source to say [Para1]. Now my problem is if I open
the report it is showing the value of unbound text box as
below:

"Thank you, " & [First Name] & " for your donation"

But actually I want [First Name] should be replaced by the
name of the customer.

Hope you understand my problem. kindly help how to solve
it. Thanks for any help.

krish

-----Original Message-----
In Access 2000 and later, you can use the Replace() function to replace the
text in the memo field with the value from the field.

For example, if your memo field contains:
Thank you, <firstname>, for your donation
then on your report, you would use a text box with ControlSource of:
=Replace([MyMemo], "<firstname>", [First Name])

Make sure the Name of this text box is not the same as the name of a field:
that causes an error in Access.

If you have lots of these replacements to make, it is probably easiest to
write a function that opens the table of replacements and loops through all
those records to perform each replacement, returning the resultant string.


Hi! Everybody, Please help me........

I want to give user to design a letters of his own. For
which I design a form which stores the value of control
source of the report in a table. like para1, para2, etc.
value of para1 is like "<some text> & [First Name] & <some
text>". The text ofcourse in quotation marks. Now I would
like to place a textbox, whose control source should be
the value of para1. I tried like the below

I am assigning [Para1] as control source to
an unbound text box in my report say [Text1]. When I open
the report it is showing the code as stored in the table
field [Para1]. But actually I want in the output [field1]
should be replaced with the value of the field. kindly
help. Thanks for any help.

krish
 
K

KRISH

Its giving error message.
"You Cannot set controlsourse property print preview or
after printing is started".

If i write the code in report open event its working fine
but my problem is not solved. because the control source
should change. which can be achieved if code works in
format event. kindly help.

thanks

krish
-----Original Message-----
Krish, to do that you would need to use an unbound text box. Then in the
Format event of the section that contains this text box, lookup the values
in the table, and assign the result to the Control Source of your text box,
with an Equal sign at the start.

Something like this:

Private Sub Detail_Format(...
Dim varResult as String
varResult = DLookup("Para1", "Table1")
If IsNull(varResult) Then
Me.MyTextbox.ControlSource = vbnullstring
Else
Me.MyTextbbox.ControlSource = "=" & varResult
End If
End Sub

My guess is that it would be more efficient to place a token in the para1
field, and use Replace() rather than reassign the text box for each record.

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

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

Thanks but I think you could not get my problem.

I have created a Table1 with field [Para1]. Now I am
storing a value in [Para1] like,

"Thank you, " & [First Name] & " for your donation"

[First Name] is the field of another tabel say [Customer].

In the report I am placing a unbound text box and set its
control source to say [Para1]. Now my problem is if I open
the report it is showing the value of unbound text box as
below:

"Thank you, " & [First Name] & " for your donation"

But actually I want [First Name] should be replaced by the
name of the customer.

Hope you understand my problem. kindly help how to solve
it. Thanks for any help.

krish

-----Original Message-----
In Access 2000 and later, you can use the Replace() function to replace the
text in the memo field with the value from the field.

For example, if your memo field contains:
Thank you, <firstname>, for your donation
then on your report, you would use a text box with ControlSource of:
=Replace([MyMemo], "<firstname>", [First Name])

Make sure the Name of this text box is not the same as the name of a field:
that causes an error in Access.

If you have lots of these replacements to make, it is probably easiest to
write a function that opens the table of replacements
and
loops through all
those records to perform each replacement, returning
the
resultant string.
Hi! Everybody, Please help me........

I want to give user to design a letters of his own. For
which I design a form which stores the value of control
source of the report in a table. like para1, para2, etc.
value of para1 is like "<some text> & [First Name] & <some
text>". The text ofcourse in quotation marks. Now I would
like to place a textbox, whose control source should be
the value of para1. I tried like the below

I am assigning [Para1] as control source to
an unbound text box in my report say [Text1]. When I open
the report it is showing the code as stored in the table
field [Para1]. But actually I want in the output [field1]
should be replaced with the value of the field. kindly
help. Thanks for any help.

krish


.
 
K

KRISHNA

I tried the same as u advised. Format event of the Details
section in which the text box is placed. Giving the error

"You Cannot set controlsourse property print preview or
after printing is started".

krish
 
A

Allen Browne

How about the alternative approach, then, of using Replace() on the token(s)
in the field?
 

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