0

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
Erik A
  • 31,639
  • 12
  • 42
  • 67
  • What is `file.Item` and where does it come from? – Andre Oct 21 '16 at 13:14
  • @Andre, it was my best guess on coding to save the jpg. It was offered by intellisense as an option, and it failed. Since nothing else I had tried was working, and gave up and tried here. I've figured out that the object must be referenced but I don't know the syntax to do it and have the file successfully save for opening later. That's where I need help. – trappertam Oct 21 '16 at 17:38
  • What are you actually trying to do? Create and save an empty .jpg file? What's the point of that? Or is there image data you want to save? Where does it come from? – Andre Oct 21 '16 at 21:32
  • My apologies for the weekend delay. An image is being uploaded from a user's computer to be held in a file on the server separate from, but linked to and available to, users of the db. If I could figure out how to use vba inside the db to operate the scanner and save jpg, jpeg, pdf & tif files as well, I would, but since I have not been able to find that, I am relegated to allowing the user the ability to operate the scanner to save to their desktop, then upload from the desktop into the db to allow the link to the customer file. Does that help? – trappertam Oct 24 '16 at 13:19
  • @Andre, perhaps it would help to know that I am new to Access and VBA. Did I answer your question the way you needed? – trappertam Oct 25 '16 at 14:20
  • Not really... If the image already exists as a file, then all you need is `FileCopy`, isn't it? Certainly not `CreateObject`. If the user has no access to the server folder, Access won't either. – Andre Oct 25 '16 at 15:40
  • @Andre, from what I've been able to find in researching 'FileCopy', it requires both a source and destination be named in VBA. If it is 'FileCopy', how would that be written to accomplish my task? Perhaps this better answers what I am looking to accomplish: from inside Access, users need to be able to upload a jpg residing on their desktop/laptop/tablet to their choice of customer's file. The customer's file is held on the db server and is linked to the customer record in the db. – trappertam Oct 25 '16 at 18:56
  • By "customer's file" you mean a folder (something like `\\server\share\customer_files\customerX` ?) – Andre Oct 25 '16 at 20:54
  • @Andre, yes, exactly. It is a file on the server held specifically under the customer's name, specified to hold all documents and pictures related to them. – trappertam Oct 26 '16 at 11:59
  • I apologize I haven't been better able to verbalize my intentions. :( – trappertam Oct 26 '16 at 12:01

1 Answers1

0

What I conclude from the discussion:

You want a msoFileDialogFilePicker dialog, not msoFileDialogSaveAs, to let the user select a file from his desktop (or wherever).
See How to show "Open File" Dialog in Access 2007 VBA?

Then read the customer folder path (server path) from your customer table (e.g. with DLookup).

Use FileCopy to copy the selected file to the server path.

If you have a table with all customer files, add Server Path\file name to it.

Note: you really need to watch the distinction of file vs. folder, or everyone is confused.

Community
  • 1
  • 1
Andre
  • 26,751
  • 7
  • 36
  • 80
  • thank you for the answer! I'll try to work it out, and let you know how it goes. I honestly did not know there is a difference between a file and a folder. Like I said, new to Access; to me, until now, they have been synonyms for the same concept. I will also look up the difference in file vs. folder. Thank you for that education, as well :) – trappertam Oct 26 '16 at 13:38
  • You are scaring me a little. :o) -- http://pc.net/helpcenter/answers/difference_between_files_and_folders – Andre Oct 26 '16 at 14:18
  • this works beautifully! Thank you very much for the education, I had no idea the difference between a file and a folder and looked it up as soon as you mentioned it, and will endeavor to be more clear in the future. I actually used a SQL query instead of 'DLookup', as 'DLookup' slows down the db too much. I was also able to combine all the documents into one button instead of separating them into single buttons; yay for smaller code! All because of your help. You're a blessing! Thank you again. – trappertam Oct 26 '16 at 14:36
  • Cool, thanks for the feedback. It is always good to know that time was well-invested. :) – Andre Oct 26 '16 at 15:16