所以我在Access中有一个子程序,它基于用户名创建一个文件夹,但是我想知道的是,如何将文件路径保存到表的字段中。
这是我的代码,我想strFolder
保存到表ImageFilePath
中名为Table_Users
的字段中
Private Sub btnSaveClose_Click()
Const strParent = "\\dlreng01\Roberts$\Access\Images\"
Dim struserID As String
Dim strFolder As String
Dim fso As Object
' Get user ID from control
struserID = Me.UserName
' Full path
strFolder = strParent & struserID
' Create FileSystemObject
Set fso = CreateObject("Scripting.FileSystemObject")
' Check whether folder exists
If fso.FolderExists(strFolder) = False Then
' If not, create it
fso.CreateFolder strFolder
End If
' Open it
Shell "explorer.exe " & strFolder, vbNormalFocus
End Sub
答案 0 :(得分:0)
一种实现方式:
Public Sub Test()
AddFilePath "MyFilePath" 'strParent & struserID
End Sub
Public Sub AddFilePath(strFolder As String)
Dim rst As DAO.Recordset
Set rst = CurrentDb.OpenRecordset("Table_Users", dbOpenDynaset)
With rst
.AddNew
.Fields("ImageFilePath") = strFolder
.Update
.Close
End With
Set rst = Nothing
End Sub