我正在尝试获取MS Access数据库,以便在导入时添加文件名称(
名为“Name”的String变量
)。该表称为“tbl_feed_import”,我需要更新的列是“F26”。我需要更新表中的每条记录,所以我省略了更新语句的WHERE部分。
然而,当我运行我的导入功能时,我得到的是“& name&”而不是实际的文件名(是的,我知道现在这将包括文件路径)。
以下是我的代码:
Public Sub Import_File()
DoCmd.RunSQL "Delete * from tbl_feed_import"
Dim feedfile, rec_count
Dim db As Database
Dim rs As Recordset
Set db = CurrentDb
Dim name As String
feedfile = FindfileXLS(CurrentProject.Path & "\Feed\")
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel5, "tbl_feed_import", feedfile, False, "Timecards data!A2:AC"
name = feedfile
'Test to see if the "name" variable can be passed to a text box
MsgBox name, vbOKOnly, "Imports Completed"
strSQL = "UPDATE tbl_feed_import" & "SET F26= '" & name & "' "
DoCmd.RunSQL strSQL
DoCmd.OpenQuery "qry_append_import_to_consolidated", acViewNormal
Exit_Route:
Set db = Nothing
Set rs = Nothing
Exit Sub
End Sub
任何帮助将不胜感激!
答案 0 :(得分:0)
当您声明“名称”变量
时,您正在使用reserved word我的建议:
Dim name As String
替换为Dim strName As String
'name
替换为strName
strSQL = "UPDATE tbl_feed_import SET F26= '" & name & "' "