Solved

Adding record with code to Hyperlink datatype in Table

Posted on 2008-06-25
1
1,083 Views
Last Modified: 2013-11-29
I have a list box that is plugged into a table with that only has one field, it is a hyperlink field.  

I want to give the user the option of adding a new hyperlink to the listbox.  Which means, adding a new record to the table the listbox is plugged into.

Once the user clicks the "Add Hyperlink" button, I have it pop open a new form with 2 textbox's and a button.

The first textbox is the hyperlink name or text that is displayed, the second textbox is for the URL.  

Can someone give me some sample VBA code on how to add the strings for the 2 textbox's to a hyperlink field?  

Not sure how to do it...  Not real good with Access yet.   I am using Access 2003.   I noticed in order to get the URL correctly out of the hyperlink field, you have to use HyperlinkPart method and it parses the database record that is hyperlink type.  

Thanks...
0
Comment
Question by:strong-daniel
1 Comment
 

Accepted Solution

by:
strong-daniel earned 0 total points
ID: 21870472
I figured this out and it was simple.  Here is the code...

Private Sub cmdAddHyperlink_Click()
On Error GoTo Err_CmdAddHyperLink_Click

   
   ' DoCmd.GoToRecord , , acNewRec
     
     Dim sNewHyperLink As String
     Dim sNewHyperLinkName As String
     Dim sNewHyperLinkURL As String
     Dim sHyperLinkRecord As String
     
     TxtHyperLinkName.SetFocus
     sNewHyperLinkName = TxtHyperLinkName.Text
     
     TxtHyperLinkURL.SetFocus
     sNewHyperLinkURL = "#" & TxtHyperLinkURL.Text & "#"
     
     sHyperLinkRecord = sNewHyperLinkName & sNewHyperLinkURL
     
     DoCmd.RunSQL "Insert into [tblMainMenuLinks] (MainMenuHyperlink) values ('" & sHyperLinkRecord & "')"
     
   
     
Exit_CmdAddHyperLink_Click:
    Exit Sub

Err_CmdAddHyperLink_Click:
    MsgBox Err.Description
    Resume Exit_CmdAddHyperLink_Click
   
End Sub
0

Featured Post

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question