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

vito1010

Registered User.
Local time
Today, 10:31
Joined
Aug 14, 2014
Messages
34
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 Office 2007.

Any help would be greatly appreciated.

Vito
 
You need three things, file dialog for selecting the file, a function for moving the file and another function for renaming the file.

So look into:

1. File Dialog in VBA or use the following API:
http://access.mvps.org/access/api/api0001.htm

2. To move the file look into FileCopy

3. To rename the file look into Name

As an alternative for 2 and 3 you can also look into the FileSystemObject.
 
I've looked around and found this:

I've looked around and found this:

Code:
   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
 
Thank you. I found the answer I was looking for. References in VBA!
 

Users who are viewing this thread

Back
Top Bottom