Results 1 to 7 of 7
  1. #1
    vito1010 is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Aug 2014
    Posts
    7

    How can I select a file (jpg) and copy (and rename) it .

    I have a model database. It has a record for each model. I (finally)
    figured out how to add an image to the record (I have a jpg in a directory
    that is the models first name and the first 3 letters of her last name
    (taken from the open form). In VBA I check if the file exists, if not, it
    puts a "Photo not found" image, if it does, it loads the image.

    I made a new small form (based on the same table) that only contains the
    ID, Last Name and First Name. I want to put a button that will open a


    dialog box to find a photo (of the model), the when selected, copy the jpg
    to the proper directory and rename it with my standard ("c:\book88\mm\" &
    [First Name] & Left([Last Name], 3) & ".jpg"). I've found examples online
    but they all get errors. I am running Access 2007.

    Any help would be greatly appreciated.


    Vito

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    FileDialog a fairly common topic. Here is one https://www.accessforums.net/program...ble-41094.html

    FileCopy also has its share of threads. Review https://www.accessforums.net/access/...opy-45903.html
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    vito1010 is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Aug 2014
    Posts
    7
    I've looked around and found this:

    Dim fDialog As Office.FileDialog
    Set fd = Application.FileDialog(msoFileDialogFilePicker)
    Dim varFile As Variant



    ' Set up the File Dialog. '
    Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
    fd.InitialFileName = [Application].[CurrentProject].[Path]
    With fDialog

    ' Allow user to make multiple selections in dialog box '
    .AllowMultiSelect = False

    ' Set the title of the dialog box. '
    .Title = "Please select a Image"

    ' Clear out the current filters, and add our own.'
    .Filters.Clear
    .Filters.Add "All Files", "*.*"

    ' Show the dialog box. If the .Show method returns True, the '
    ' user picked at least one file. If the .Show method returns '
    ' False, the user clicked Cancel. '
    If .Show = True Then

    filecopy([.SelectedItems], fName)

    ' fName is the path and file name from the form. It is '
    ' "c:\book88\mm\" & [First Name] & Left([Last Name], 3) & ".jpg"

    Else

    End If
    End With
    End Sub


    When I click the button to execute, I get an error:
    User-defined type not defined

    This is the highlighted line when I click on Debug:
    Dim fDialog As Office.FileDialog

    Any assistance would be greatly appreciated.

    ViTo

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Did you review the referenced link? Did you set the MS Office Object library reference?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    vito1010 is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Aug 2014
    Posts
    7
    Thank you for the response. I am not really familiar with VBA except what I pick up (and adapt) on the net. How do I go about setting the reference?

    Thank You In Advance,

    ViTo

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    From VBA editor menu bar > Tools > References
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    vito1010 is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Aug 2014
    Posts
    7
    THANK YOU SO MUCH!

    It works great now!

    Thanks again!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Copy/paste/rename a field in the same form?
    By Jamesiv1 in forum Access
    Replies: 5
    Last Post: 04-26-2014, 10:22 AM
  2. rename a PDF File
    By sdel_nevo in forum Programming
    Replies: 3
    Last Post: 08-21-2013, 12:11 PM
  3. Replies: 4
    Last Post: 10-30-2012, 02:54 PM
  4. Copy & Rename a report
    By Juanna_v in forum Reports
    Replies: 25
    Last Post: 02-17-2011, 12:03 PM
  5. Have access rename a .txt file and move it
    By dh010010 in forum Programming
    Replies: 5
    Last Post: 07-22-2010, 10:49 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums