Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Print document from access with file name same as value in field

Status
Not open for further replies.

toolman2

Technical User
Jul 31, 2001
12
Hi all,

Ok....I've looked through all the postings til blue in the face and cannot figure out how to do what I want to do.

I have a form to which I want to add a command button that will prompt the user for two dialog boxes asking for input that will result in:
a) printing a (not necessarily the same) report based on the input to the dialog boxes.
b) printing an associated (text) document where the name of the file is the same as a value in a certain field in my report.

For ex:
User clicks on button and is prompted to enter the machine number, hits enter and then is prompted for the toolkit number, hits enter. A report will be printed that is designed for that particular machine and a document whose file name (ex: 0001.ncs) is the same as the value in a field (Tl Number) where another field (Prefix) equals "TP".

***Print document where prefix = "TP" and Tl Number = document's file name***

I know how to create the command button with the prompts and that will print the report and then open up a document outside of access, but here's my problem. I don't know how (or where) to enter code that will relate the linking (Tl Number) field's value to the document file so that it will know which document to print.

I don't need to see the report or the document, just print them out. I'm pretty code stupid, just learning (slowly) on my own and would appreciate any help.

Thanks,
Kevin
 
for the report:

docmd.openreport acreport, acviewnormal ' this prints the report, acviewpreview displays it oncreen

for the textfile:

lblOpenReport_click()

const strFolder as string = "C:\Some\Path\That\Your\File\Is\In\"

dim strFile as string
strFile = [an expression for the field on your report here]

me.lblOpenReport.hyperlinkaddress = strFolder & strFile

this will open the text file (provided you come up with an expression for where to look for its filename that access is capable of reading), you'll still have to print it by hand, but this is a step in the right direction and much simpler than some other methods i've seen to show/print files.

 
Thanks Spiralmind for your reply.
I'll play around with it and see if I can get something to happen.
Another question.....If I have in a field, a link to the file I want to output, how could I make that happen when I'm printing out my report?

Thanks
 
make what happen?

by the way: do you want to print to or to print from the textfile? i gave a way to open an existing file, not a way to write to one. to write to the file you'll have to use the 'TransferText' function (look it up in the access help files) to export the text to a file (you can still specify the file name and pull it from your report if the report is in scope). if the textfile is supposed to be the same as the report i know you can export the report to a textfile (or excell, or rtf...) directly after previewing it, though i'm not so sure of how you would automate that (though there must be a way). if you choose rtf as your export format you'll produce a nice, clean, formatted report that will open and display beautifully in msWord (the ascii won't be as pretty, but might be just what you need if you're sending off to some archive or pre-existing system). try it - and post your final solution when you find a way to get it to do what you want. if i'm not on the right track as far as what you're trying to do, though, please clarify so i can better be of service (i have all my posts on email notification, so i'll probably notice any new developments)

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top