Form coding Help - Part 2

B

BaWork

I'm using the following code to set the report name of a snapshot file
on save and it works perfectly.

*************************

Private Sub cmd_save_report_Click()
On Error GoTo Err_cmd_save_report_Click

Dim stDocName As String

stDocName = first_name & "_" & last_name & "_resume"
DoCmd.OutputTo acReport, stDocName, acFormatSNP

Exit_cmd_save_report_Click:
Exit Sub

Err_cmd_save_report_Click:
MsgBox Err.Description
Resume Exit_cmd_save_report_Click

End Sub

*************************

If I transfer the same coding logic to send a snapshot file through
email, I get the following error:

"The report name "first_last_resume" you entered in either the property
sheet or macro is misspelled or refers to a report that doesn't exist."

Here is my current code.

*******************************

Private Sub cmd_email_report_Click()
On Error GoTo Err_cmd_email_report_Click

Dim stDocName As String

stDocName = first_name & "_" & last_name & "_resume"
DoCmd.SendObject acReport, stDocName, acFormatSNP

Exit_cmd_email_report_Click:
Exit Sub

Err_cmd_email_report_Click:
MsgBox Err.Description
Resume Exit_cmd_email_report_Click

End Sub

*******************************

Thanks

Brett
 
D

Dirk Goldgar

BaWork said:
I'm using the following code to set the report name of a snapshot file
on save and it works perfectly.

*************************

Private Sub cmd_save_report_Click()
On Error GoTo Err_cmd_save_report_Click

Dim stDocName As String

stDocName = first_name & "_" & last_name & "_resume"
DoCmd.OutputTo acReport, stDocName, acFormatSNP

Exit_cmd_save_report_Click:
Exit Sub

Err_cmd_save_report_Click:
MsgBox Err.Description
Resume Exit_cmd_save_report_Click

End Sub

*************************

If I transfer the same coding logic to send a snapshot file through
email, I get the following error:

"The report name "first_last_resume" you entered in either the
property sheet or macro is misspelled or refers to a report that
doesn't exist."

Here is my current code.

*******************************

Private Sub cmd_email_report_Click()
On Error GoTo Err_cmd_email_report_Click

Dim stDocName As String

stDocName = first_name & "_" & last_name & "_resume"
DoCmd.SendObject acReport, stDocName, acFormatSNP

Exit_cmd_email_report_Click:
Exit Sub

Err_cmd_email_report_Click:
MsgBox Err.Description
Resume Exit_cmd_email_report_Click

End Sub

*******************************

Thanks

Brett

Are you sure there's a report in your database named
"first_last_resume"? I don't see anything wrong with your coding, so
long as that report exists.
 
B

BaWork

There is not a report with that name, I want the file name to be
dynamically generated like it is for the "Save" command that I use.

In the "Save" command example, the code pulls the applicatant's first
and last name from the form to set the default file name.
 
D

Dirk Goldgar

Interesting. I wouldn't expect the code you posted for the "Save"
example to work that way, and indeed it doesn't in my quick test. Are
you sure that's the code you're using? If so, in what context are you
executing it? If the report by that name doesn't exist, how does Access
know what report you want to output?

I would expect the "save" code to be more like this, assuming that it's
supposed to save the active report:

DoCmd.OutputTo acReport, , acFormatSNP, stDocName

But SendObject doesn't provide the functionality to specify the name of
the file attachment to be sent. You could output the report to a file
with the appropriate name, and then use one of several techniques to
create an e-mail and attach that file; see Tony Toews' Access E-Mail
FAQ:

http://www.granite.ab.ca/access/email.htm
 
B

BaWork

Dirk,

I must apologize, I did some more testing and you are correct. I was
only going as far as seeing if the file name listed in the save dialog
box was what I wanted and it was. When I actually tried to save the
report, it didn't work.

I was implementing the advice I got from a previous post.

So back to square one...and my question...

How do I preset the name of the snapshot file that is either getting
saved to a file or emailed as an attachment? I want to pull the first
and last name from the form and name the file "firtname_lastname.snp".
Here is the correct code that Access generates without the feature of
presetting the file name:

*************************

Private Sub cmd_save_report_Click()
On Error GoTo Err_cmd_save_report_Click

Dim stDocName As String

stDocName = "rpt_resume"
DoCmd.OutputTo acReport, stDocName, acFormatSNP

Exit_cmd_save_report_Click:
Exit Sub

Err_cmd_save_report_Click:
MsgBox Err.Description
Resume Exit_cmd_save_report_Click

End Sub

**************************

Thanks again for your complete testing...something I failed to do.

Brett
 
B

BaWork

Dirk,

I must apologize, I did some more testing and you are correct. I was
only going as far as seeing if the file name listed in the save dialog
box was what I wanted and it was. When I actually tried to save the
report, it didn't work.

I was implementing the advice I got from a previous post.

So back to square one...and my question...

How do I preset the name of the snapshot file that is either getting
saved to a file or emailed as an attachment? I want to pull the first
and last name from the form and name the file "firtname_lastname.snp".
Here is the correct code that Access generates without the feature of
presetting the file name:

*************************

Private Sub cmd_save_report_Click()
On Error GoTo Err_cmd_save_report_Click

Dim stDocName As String

stDocName = "rpt_resume"
DoCmd.OutputTo acReport, stDocName, acFormatSNP

Exit_cmd_save_report_Click:
Exit Sub

Err_cmd_save_report_Click:
MsgBox Err.Description
Resume Exit_cmd_save_report_Click

End Sub

**************************

Thanks again for your complete testing...something I failed to do.

Brett
 
D

Dirk Goldgar

BaWork said:
Dirk,

I must apologize, I did some more testing and you are correct. I was
only going as far as seeing if the file name listed in the save dialog
box was what I wanted and it was. When I actually tried to save the
report, it didn't work.

I was implementing the advice I got from a previous post.

So back to square one...and my question...

How do I preset the name of the snapshot file that is either getting
saved to a file or emailed as an attachment? I want to pull the first
and last name from the form and name the file "firtname_lastname.snp".
Here is the correct code that Access generates without the feature of
presetting the file name:

*************************

Private Sub cmd_save_report_Click()
On Error GoTo Err_cmd_save_report_Click

Dim stDocName As String

stDocName = "rpt_resume"
DoCmd.OutputTo acReport, stDocName, acFormatSNP

Exit_cmd_save_report_Click:
Exit Sub

Err_cmd_save_report_Click:
MsgBox Err.Description
Resume Exit_cmd_save_report_Click

End Sub

**************************

Thanks again for your complete testing...something I failed to do.

Brett

Okay, Brett, try something like this:

'----- start of code -----
Private Sub cmd_save_report_Click()
On Error GoTo Err_cmd_save_report_Click

Dim stDocName As String
Dim stFolder As String
Dim stFileName As String

stDocName = "rpt_resume" ' report name

stFolder = CurrentProject.Path ' folder to store snapshot file
' Note: the above will store the file in the same folder as the
' database. You could hard-code some other folder, or
' save to the user's My Documents folder, or otherwise
' choose a folder to save into.

' Set output file name.
stFileName = Me!first_name & "_" & Me!last_name & "_resume.snp"

DoCmd.OutputTo acOutputReport, stDocName, acFormatSNP, _
stFolder & "\" & strFileName

Exit_cmd_save_report_Click:
Exit Sub

Err_cmd_save_report_Click:
MsgBox Err.Description
Resume Exit_cmd_save_report_Click

End Sub
'----- end of code -----
 
B

BaWork

I gave it a shot and it didn't work - I got an error about how there
wasn't enough memory in the temporary folder to create the file...

I'm not sure how that is possible...

Unless there is something else I can try, I'm going to give up on what
would have been a nice little feature.

Thanks again.

Brett
 
D

Dirk Goldgar

BaWork said:
I gave it a shot and it didn't work - I got an error about how there
wasn't enough memory in the temporary folder to create the file...

I'm not sure how that is possible...

Unless there is something else I can try, I'm going to give up on what
would have been a nice little feature.

You give up way too easily, Brett!

That's a misleading message. You'll get that message if the name of file
you're trying to create isn't valid, either because it contains a
character that isn't permitted in file names, or because the folder path
is not valid. Check the name and folder path of the file you're trying
to create. If you can't figure out the problem, post the code you're
now using and the values of the form controls and variables that are
involved.
 

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

Similar Threads


Top