How do I access form or report field data dynamically

L

Leighton.d

I have a generic report that's essentially a letter. The user can create
their own letter using keywords I've designated. It works like a mail merge
where the keywords are replaced with data from a table. Some of the data
needs to be reformatted. I have the keywords in a table. One of the fields
contains the name of the corresponding field in the report that gets inserted
where its keyword is found.

When the report (letter) is generated, the letter the user created is
contained in one memo field that gets read into a single variable when the
report is opened. I've attached code to the Detail - On Format event that
makes a copy of the memo field, then searches and replaces for the keywords
and replaces them with the data from the current record.

I need to know how to transfer the data from a field on the report into a
variable so that I can perform any reformatting if needed. I don't want
anything hard coded into the report so that I can add additional keywords
down the road.

Hope this makes sense!

Thanks...
 
M

Marshall Barton

Leighton.d said:
I have a generic report that's essentially a letter. The user can create
their own letter using keywords I've designated. It works like a mail merge
where the keywords are replaced with data from a table. Some of the data
needs to be reformatted. I have the keywords in a table. One of the fields
contains the name of the corresponding field in the report that gets inserted
where its keyword is found.

When the report (letter) is generated, the letter the user created is
contained in one memo field that gets read into a single variable when the
report is opened. I've attached code to the Detail - On Format event that
makes a copy of the memo field, then searches and replaces for the keywords
and replaces them with the data from the current record.

I need to know how to transfer the data from a field on the report into a
variable so that I can perform any reformatting if needed. I don't want
anything hard coded into the report so that I can add additional keywords
down the road.


Here's some air code that outlines the general idea. Be
sure to check Help on any parts that you are not familiar
with.

Dim db As Database
Dim rs As DAO.Recordset
Dim strMemo As String

Set db = CurrentDb()
Set rs = db.OpenRecordset("keywordstable", dbOpenSnapshot)
strMemo = Me.memotextbox

Do Until rs.EOF
strMemo = Replace(strMemo, rs!keywordfield, rs!datafield)
Loop
Me.lettertextbox = strMemo

rs.Close : Set rs = Nothing
Set db = Nothing
 
L

Leighton.d

Thanks for the ultra quick response! I believe I've spotted what I need in
the code contained within the database.
 

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