从表单到表访问VBA SQL插入超链接 [英] Inserting Hyperlink from Form to Table Access VBA SQL

查看:220
本文介绍了从表单到表访问VBA SQL插入超链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过VBA将表单上输入的超链接(作为超链接)带到它需要访问的表。我正在使用Access 2010.
它一直给我一个SQL语句错误。我知道这与超链接#的标志有关。我不太了解如何处理超链接。我已经阅读了很多论坛帖子,但它们都不同(不同年份),我似乎无法破解他们的例子来满足我的需求。
任何人都可以让我知道我做错了什么?谢谢

I am wanting to take the hyperlink that is entered on a form (As a hyperlink) to the table it needs to go to, through VBA. I am using Access 2010. It keeps giving me a SQL statement error. I know it has to do with the hyperlink #'s signs. I do not quite grasp how hyperlinks are handled. I have read plenty of forum posts, but they all are different (Different years), and I can't seem to hack up their examples to meet my needs. Can anyone please let me know what it is that I am doing wrong? Thanks

Private Sub SaveReq_Click()
' 
' Saves the current entry to the database
' Into the TABLE 'pr_req_table'
' 

' Open a connection to the database
dim data_base as Database
set data_base = OpenDatabase(CurrentProject.Path & "\test_database.accdb")

' Grab all information from form
' Add information to pr_req_table
data_base.Execute "INSERT INTO pr_req_table " _
    & "(pr_no, pr_date, pr_owner, pr_link, pr_signed) " _
    & "VALUES (" & pr_num.Value & ", #" &  Format(pr_date.Value, "mm/dd/yyyy") & "#, " _
        &  List22.Value & ", " & "Excel Copy #" & elec_copy.Value & ", " & "Signed Copy #" & sign_copy.Value & ");"

' Close Database connection
data_base.Close

End Sub

提前感谢您的帮助!

Nathan

推荐答案

我将使用如下参数查询:

I would use a parameter query as follows:

Sub InsertRecord()
Dim data_base As Database
Set data_base = OpenDatabase(CurrentProject.Path & "\test_database.accdb")

' Grab all information from form
' Add information to pr_req_table
Dim qd As QueryDef
Set qd = data_base.CreateQueryDef("")
qd.sql = "INSERT INTO pr_req_table(pr_no, pr_date, pr_owner, pr_link, pr_signed) " & _
    "values([p1],[p2],[p3],[p4],[p5])"
qd.Parameters("p1").Value = pr_num.Value
qd.Parameters("p2").Value = Format(pr_date.Value, "mm/dd/yyyy")
qd.Parameters("p3").Value = List22.Value
qd.Parameters("p4").Value = "Excel Copy #" & elec_copy.Value
qd.Parameters("p5").Value =  "Signed Copy #" & sign_copy.Value 
qd.Execute

End Sub

这篇关于从表单到表访问VBA SQL插入超链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆