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:

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
What happens if you remove these two lines from your code?
VBA Code:
    f.FilterOn = False
    Set f = Nothing
 
Upvote 0
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
 
Upvote 0
By any chance is the button on form CallLogEntryForm? If so, you don't need much of that code.
 
Upvote 0

Forum statistics

Threads
1,214,585
Messages
6,120,399
Members
448,958
Latest member
Hat4Life

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