Avatar of kixelsyD
 asked on

"Access 2010", Referance a Text Field within another Text Field in a report.

I am trying to create an Access 2010 DB that will create a report for requesting travel. The DB is all set up with Tables, Queries, forms and a Single Report.
In the report, I have a field that gives the explanation on when and where the travel will be.
Such as:
"I will be traveling on [date] and going to [Location] and returning on [Date]."
What I would like to do is to have a template text and have the dates and location embedded into the text. The idea is to have a database that will record the requests and have a standardized document to be printed. The static text is a "Label" and not a text field.

Any suggestions would be great.

Thank you for your time,
Microsoft Access

Avatar of undefined
Last Comment
Jeffrey Coachman

8/22/2022 - Mon

Use the Replace() function to replace the token with the actual date.

replace(Me.yourcontrol.Caption, "[Date]", Me.datefield)

If that gives you an error (you may not be able to replace the caption on the fly), then change it to a text box and keep the string in your code as a variable or keep it in a table and get it when you need it.  Using a table gives you more flexibility and will allow a user to change it rather than the programmer having to change is.
Dale Fye

Another options would be to create a function that returns your not-so static text, something like:

Public Function fnTravelRequest(dtDepart as variant, _
         strLocation as variant, dtReturn as variant) as string

fnTravelRequest = "I will be traveling on " _
     & iif(IsNull(dtDepart), "TBD", Format(dtDepart, "dd mmm, yy")) _
     & " and going to " & NZ([Location], "TBD") _
     & " and returning on " _
     & iif(IsNull(dtReturn), "TBD", Format(dtReturn, "dd mmm, yy"))

End Function

Open in new window

Jeffrey Coachman

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question

Thanks Jeff,

After looking at the DB, I went with just creating a simple query.

This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
Jeffrey Coachman

ok, great, ...glad I could help