1

Is it possible to create via VBA a hyperlink, which could be included in the body of an email, to open a form in an Access database at a given record?

I've tried with the code below:

Private Sub Create_Link_To_Open_Form()

   Dim outlookApp as Outlook.Application
   Set outlookApp = New Outlook.Application

   Dim record_email As Outlook.MailItem
   Set record_email = outlookApp.CreateItem(olMailItem)

   Dim stringBody, strlink  As String

   record_email.To = "foo_user@foo.com"
   record_email.Subject = "example subject"

   'The link should open the form "example_form" at the record with ID=1 
   string_path = "C:\Path\example_db.accdb?Form=example_form%ID=1"
                    
   stringBody = "Click " & "<a href=" & strlink & ">Here</a>" & " to 
                open the record" & "<br>" _
                & "Thank you."

   With record_email
       .HTMLBody = .HTMLBody & stringBody
   End With

   record_email.Display

End Sub

And basically the link did not work.

If I just try to open the example_db as in:

string_path = "C:\Path\example_db.accdb"

It works perfectly, so it must necessarily be something to do with how to insert the name of the form and the record within the link, assuming this is possible in the first place.

  • Access can't use URL parameters, but command-line parameters work. You can pass any string and then parse it in AutoExec. See [here](https://stackoverflow.com/questions/43176599/opening-microsoft-access-with-parameters) for the basics, and [here](https://stackoverflow.com/questions/67993711/how-to-send-html-attachment-including-hyperlink-in-email-body-with-outlook) how to use this in links in emails. – Andre Apr 26 '23 at 15:28
  • @Andre Thanks for the answer, I thought about /cmd option. Creating a shortcut, and adding the /cmd at the end of the target. Something I did not mention and maybe I should have is that, the record to be accessed will be different every time, therefore the link will be different. – hectoruhalte Apr 27 '23 at 08:53
  • I'm afraid I am not allowed to "play" with the Windows Registry in my organisation. I will check the solution provided by Andre "at home", it looks promising, and make sense. – hectoruhalte Apr 27 '23 at 12:58

0 Answers0