In a DAO db, Access 2013, I am receiving a Compile syntax error on the Set Image line in the msoFileDialogSaveAs application. I'm best-guessing on the code for how to save the jpg file. After research across forums and the MS Developer/Support DB, I've experimented and this is the closest I've come to resolution. Any ideas on how to successfully allow the end user to save a jpg file to the system, but not the db itself, from inside access? I am uncomfortable using the API at this point.
Option Compare Database
Option Explicit
Dim FileLocation As String
Dim DiagFile As FileDialog
Private Sub Jpgbtn_Click()
Set DiagFile = Application.FileDialog(msoFileDialogSaveAs)
DiagFile.Title = "Save .jpg File As..."
DiagFile.InitialFileName = "*.jpg"
DiagFile.AllowMultiSelect = False
If DiagFile.Show Then
FileLocation = DiagFile.SelectedItems(1)
Set Image = CreateObject("*.jpg")
>>>>>Set Image = file.Item "*.jpg"
Image.SaveFile FileLocation
End If
MsgBox (" Jpg successfully saved. ")
globals.ActivityLog "Jpgbtn"
End Sub
答案 0 :(得分:0)
我从讨论中得出结论:
您希望msoFileDialogFilePicker
对话框而不是msoFileDialogSaveAs
让用户从桌面(或任何地方)选择文件。
见How to show "Open File" Dialog in Access 2007 VBA?
然后从客户表中读取客户文件夹路径(服务器路径)(例如,使用DLookup
)。
使用FileCopy
将所选文件复制到服务器路径。
如果您有包含所有客户文件的表格,请向其添加Server Path\file name
。
注意:您确实需要注意文件与文件夹的区别,否则每个人都会感到困惑。