Email Current record

seirra

Board Regular
Joined
Nov 7, 2002
Messages
72
Good day
My scripting skills are Nil and hoping for some help or direction where I can find the answer everything I have come across doesn’t seem to fit or be from a much older version of Access it doesn’t seem to work in Access 2010.

I would like to email just the current record I have on the screen. I have placed an email button thought the wizard but it will only email all 5000 records. How do I go about limiting it to just the current record?

Thanks for any and all assistance



Private Sub Command325_Click()
On Error GoTo Err_Command325_Click

Dim stDocName As String

stDocName = "Rpt_Word_orders"
DoCmd.SendObject acReport, stDocName

Exit_Command325_Click:
Exit Sub

Err_Command325_Click:
MsgBox Err.Description
Resume Exit_Command325_Click

End Sub
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
You can't apply a filter with the sendobject method, but you can open the report hidden and pass either a filter name or opening argument to the report. On the report open event, you check for either the filter or argument and if not null or an empty string, you apply the value you passed as a filter. Here's how to do it with the opening argument in the button click event:

Code:
DoCmd.OpenReport "rptName", acViewPreview, , , acHidden, "AssetId=1"
DoCmd.SendObject acSendReport, "6AssetT", acFormatRTF
Although it seems counter-intuitive to specify a report view then make the window hidden, if you don't it doesn't work. In the report open event, put

Code:
If Me.OpenArgs <> "" Then
    Me.Filter = Me.OpenArgs
    Me.FilterOn = True
End If

Of course, you change what's above to use your report name.
 
Last edited:
Upvote 0
Thanks for the reply.
I think I might be doing something wrong. When executed Access still attempt to send all the data and not just that for the current record. Or is it easier just to send fields from the current record. I know it won’t be as pretty but I will take what I can get.

Thanks again for the assistance


Private Sub Command331_Click()
On Error GoTo Err_Command331_Click

DoCmd.OpenReport "rpt_work_orders", acViewPreview, , , acHidden, "AssetId=1"
DoCmd.SendObject acSendReport, " rpt_work_orders ", acFormatRTF

If Me.OpenArgs <> "" Then
Me.Filter = Me.OpenArgs
Me.FilterOn = True
End If


Exit_Command331_Click:
Exit Sub

Err_Command331_Click:
MsgBox Err.Description
Resume Exit_Command331_Click

End Sub
 
Upvote 0
Interesting. It worked for me. I got an email with the attachment, and when I opened it, only 1 record was visible in the report attachment. Perhaps your report is not filtering the value. I see you used exactly what I posted (AssetID=1). You realize you cannot use that? You have to create your own filter.
 
Upvote 0
I didn't realize that I had to create a filter. Having not done a huge amount in Access I have only used the Filter selection to sort data on a table. I am not really sure how or where I would do that. I did change "AssetId=1" to "Prime Key=1" and it still tries to spit out the whole thing.

Thanks for the putting up the with basic questions
 
Last edited:
Upvote 0
Since I am guessing you can only edit once...... I think I may have found part of my problem. I was writing “Prime Key=1” vs “Prime Key”=1 but now I have an Type Mismatch error. Still trying to find out how to fix that.
 
Upvote 0
If Prime Key is text, you will generate the error by comparing it to an integer. If it is not text, try "[Prime Key]=1 "
The filter must be enclosed in quotes.
This is a good reason why I never uses spaces in my object or variable names.
 
Upvote 0
It apprears to open one report but then tries to send all reports. Since I have very limited knowedge of VB could it be the version of Access? I'm using 2010. Thanks again for all the assistance
 
Last edited:
Upvote 0
Just back from vacation, thus the late response. Post back if you still need help.
 
Upvote 0

Forum statistics

Threads
1,214,829
Messages
6,121,827
Members
449,051
Latest member
excelquestion515

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top