Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Adding record with code to Hyperlink datatype in Table

Posted on 2008-06-25
1
Medium Priority
?
1,090 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
If you’re using QODBC to update QuickBooks data from Microsoft® Access but Access is not showing the updated data, you could have set up QODBC incorrectly.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

916 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