Button to export rtf (2 Viewers)

DaveEntact

New member
Local time
Yesterday, 23:16
Joined
Oct 7, 2021
Messages
6
Trying to add a button to my form that will export ONLY one field on the form to rtf. I'm new to this so don't know the code.
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 21:16
Joined
Oct 29, 2018
Messages
16,572
Hi. Welcome to AWF!

Probably the easiest route is to create a query to return the single field you want to export and then use a macro to export it (the query).
 

conception_native_0123

Well-known member
Local time
Yesterday, 23:16
Joined
Mar 13, 2021
Messages
1,208
Hi. Welcome to AWF!

Probably the easiest route is to create a query to return the single field you want to export and then use a macro to export it (the query).
guy,

will that create designing pipes with the single field values as well? I know if tables get exported and they are opened up in notepad, the vals are surrounded by pipes. will this happen here too?
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 12:16
Joined
May 7, 2009
Messages
14,089
create a Query outputting the single field:

(qryFieldname)
select Fieldname1 from yourTable;

you can use Macro to export the query (ExportWithFormatting).
just complete the required textbox on the macro design.

use DoCmd.OutputTo, in VBA.

DoCmd.OutputTo objecttype:=acOutputQuery, objectname:="yourQueryName", outputformat:=acFormatRTF, outputfile:="d:\output.rtf"
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 21:16
Joined
Oct 29, 2018
Messages
16,572
guy,

will that create designing pipes with the single field values as well? I know if tables get exported and they are opened up in notepad, the vals are surrounded by pipes. will this happen here too?
Hi. You are correct. The exported file will contain the pipes. Are you looking for a way to not have the pipes? Since the OP is exporting it to RTF, it would have a normal table borders instead.
 

conception_native_0123

Well-known member
Local time
Yesterday, 23:16
Joined
Mar 13, 2021
Messages
1,208
Hi. You are correct. The exported file will contain the pipes. Are you looking for a way to not have the pipes? Since the OP is exporting it to RTF, it would have a normal table borders instead.
no i'm not looking for anything. i was just asking a question. thanks!
 

DaveEntact

New member
Local time
Yesterday, 23:16
Joined
Oct 7, 2021
Messages
6
create a Query outputting the single field:

(qryFieldname)
select Fieldname1 from yourTable;

you can use Macro to export the query (ExportWithFormatting).
just complete the required textbox on the macro design.

use DoCmd.OutputTo, in VBA.

DoCmd.OutputTo objecttype:=acOutputQuery, objectname:="yourQueryName", outputformat:=acFormatRTF, outputfile:="d:\output.rtf"
I'm new to this so not sure how to do this. Would I select Export_Word in Property Sheet then add [Event Procedure] then add the code there? And where would I add the qryFieldname?
 

DaveEntact

New member
Local time
Yesterday, 23:16
Joined
Oct 7, 2021
Messages
6
Ok it works with the code
DoCmd.OutputTo objecttype:=acOutputQuery, objectname:="yourQueryName", outputformat:=acFormatRTF, outputfile:="d:\output.rtf"

but that exports all the records. I want the button to export just one field from one record.
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 21:16
Joined
Oct 29, 2018
Messages
16,572
Ok it works with the code
DoCmd.OutputTo objecttype:=acOutputQuery, objectname:="yourQueryName", outputformat:=acFormatRTF, outputfile:="d:\output.rtf"

but that exports all the records. I want the button to export just one field from one record.
Make the query return only one field and only one record.
 

DaveEntact

New member
Local time
Yesterday, 23:16
Joined
Oct 7, 2021
Messages
6
Show us your query and tell us which field and which record you want.
This is the code
DoCmd.OutputTo objecttype:=acOutputQuery, objectname:="ResumeExport Query", outputformat:=acFormatRTF, outputfile:="output.rtf"

The Query just has one field listed. I want the user to be able to open the form then select a random record and click an Export to RTF button that exports a particular field on that record.
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 21:16
Joined
Oct 29, 2018
Messages
16,572
This is the code
DoCmd.OutputTo objecttype:=acOutputQuery, objectname:="ResumeExport Query", outputformat:=acFormatRTF, outputfile:="output.rtf"

The Query just has one field listed. I want the user to be able to open the form then select a random record and click an Export to RTF button that exports a particular field on that record.
Hmm, I asked you to show us your query, but you decide to show us your code instead. Unfortunately, we won't be able to answer your question from that piece of information. The code is correct, and it works. The only problem is it will export the entire content of "ResumeExport Query." So, the approach we need to take is make sure "ResumeExport Query" only contains the selected record by the user. And to do that, we'll need to see that query (ResumeExport Query). And by that, I mean, can you please post the SQL statement for that query? Thank you.
 

DaveEntact

New member
Local time
Yesterday, 23:16
Joined
Oct 7, 2021
Messages
6
Hmm, I asked you to show us your query, but you decide to show us your code instead. Unfortunately, we won't be able to answer your question from that piece of information. The code is correct, and it works. The only problem is it will export the entire content of "ResumeExport Query." So, the approach we need to take is make sure "ResumeExport Query" only contains the selected record by the user. And to do that, we'll need to see that query (ResumeExport Query). And by that, I mean, can you please post the SQL statement for that query? Thank you.
Sorry. Very new to this. Is this what you are talking about:
SELECT Contacts.[Resume]
FROM Contacts;
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 21:16
Joined
Oct 29, 2018
Messages
16,572
Sorry. Very new to this. Is this what you are talking about:
SELECT Contacts.[Resume]
FROM Contacts;
Yes, that's a good start. Okay, the query is pulling all [Resume] from the Contacts table. If there are more than one contacts, then the query will return all of them - not just one. Now, you said you wanted the user to select a contact from a form - the one they want to export. In that case, you'll have to add a WHERE clause to that query to only return the Resume for the selected Contact. Here's an example.
SQL:
SELECT [Resume] FROM Contacts WHERE ContactID=Forms!FormName.ContactID
Hope that helps...
 

Users who are viewing this thread

Top Bottom