Returning to same record

kevinh2320

Board Regular
Joined
May 13, 2016
Messages
61
I have the code below on a button "on_click" event which works but, once the email is sent and the form comes back on screen I'm returned to the first record in the table. I want it to return to the record that I just emailed. I can't seem to figure out how to to that.

VBA Code:
Private Sub email_current_record_Click()
    On Error GoTo EmailHandler
    Dim f As Form
    Set f = Forms![CallLogEntryForm]
    f.Filter = "ID=" & f!ID
    f.FilterOn = True
    DoCmd.SendObject acSendForm, f.Name, acFormatPDF, , , , "Customer Call Notification", "See attached", True, "F:\CallLog\templates\CallLogEntryFormTemplate.pdf"
  
    f.FilterOn = False
    Set f = Nothing
  
    Exit Sub
   
EmailHandler:
    MsgBox "You must enter or load a record in the form."
   
End Sub
 
Last edited by a moderator:

Some videos you may like

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
56,651
Office Version
  1. 365
Platform
  1. Windows
What happens if you remove these two lines from your code?
VBA Code:
    f.FilterOn = False
    Set f = Nothing
 

welshgasman

Well-known Member
Joined
May 25, 2013
Messages
882
You generally save the ID of the record and then return to it.?
As you are filtering then clearing the filter, you would still need to do this after clearing the filter.?

Alternatively just go to the record and then send the Form. Then you would remain on the record.

HTH
 

Micron

Well-known Member
Joined
Jun 3, 2015
Messages
2,058
Office Version
  1. 365
Platform
  1. Windows
By any chance is the button on form CallLogEntryForm? If so, you don't need much of that code.
 

Watch MrExcel Video

Forum statistics

Threads
1,127,594
Messages
5,625,693
Members
416,127
Latest member
MALEPINZON

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
Top