0

I am trying to add a record into an Access table (hyperlinks) and the field "link" should be set to "u:\directory here\" I have tried

docmd.runsql "insert into hyperlinks (link."U:\directory here\")" 

and get errors, I tried ' instead of " and I tried without the quotes, all end in error with not specification as to what is wrong.

1
  • 1
    "error with not specification as to what is wrong" - What does the error message say? "get errors" isn't very specific. Read the error messages, they're trying to tell you the problem. Commented Feb 22, 2019 at 13:14

2 Answers 2

1

I would suggest:

docmd.runsql "insert into hyperlinks (link) values ('U:\directory here\')" 

The syntax of an MS Access SQL insert statement can be found here.

Sign up to request clarification or add additional context in comments.

1 Comment

Ok beat me to it - i'll delete my answer :)
0

If your field is of type Hyperlink (rather than of type text), your SQL needs to use the following format:

Display Text#Link Path#Sub address#optional screen tip#

If you just want the link path (e.g. https://google.com), simply enclose it with the #:

INSERT INTO tHyperlinks (path) VALUES ("#https://google.com#")

More information can be found here

Personally, I don't like to use the Hyperlink data type in Access: I find it's easier to use a simple text field, and generate a hyperlink in a form.

Additionally, I would recommend against using DoCmd.RunSQL. Whenever you use this method, the user will see a confirmation message (allowing them to cancel the update), unless you turn it off: action query confirmation

To turn off this confirmation, you'd have to something like the following:

DoCmd.SetWarnings False
DoCmd.RunSQL yourSQL
DoCmd.SetWarnings True

Even worse, if the user has changed their options to not show these confirmations by default, you'll show the confirmation (when they've specifically said they don't want to view them).

It is far better to use the Database.Execute method in the DAO library:

Dim db as DAO.Database: Set db = CurrentDB
db.Execute yourSQL, dbFailOnError

The user won't get a confirmation message (regardless of their client settings), and with the dbFailOnError, an error will be generated if the record isn't added, which will give you nice detailed information (the error below is when I deleted a parenthesis):

db.execute error

You can then perform error handling.

For more information on DoCmd.RunSQL vs. Database.Execute, see these links.

Official Microsoft Docs pages you might find useful:

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.