josephbupe
Registered User.
- Local time
- Today, 13:15
- Joined
- Jan 31, 2008
- Messages
- 247
Hi.
From the code below, I want to programmatically copy and rename the files I am adding into the table tblObjects to be same as the primary key which is ObjectID, i.e. /Images/1.jpeg etc and then return the relative filepath containing all the images to be in a folder called "Images" within the current project folder.
Currently, I cant even populate the table; When i select a file through the file dialog to populate the table, i am getting this error:
Below is the code:
From the code below, I want to programmatically copy and rename the files I am adding into the table tblObjects to be same as the primary key which is ObjectID, i.e. /Images/1.jpeg etc and then return the relative filepath containing all the images to be in a folder called "Images" within the current project folder.
Currently, I cant even populate the table; When i select a file through the file dialog to populate the table, i am getting this error:
error 75 in cmdBrowse_Click procedure: path/file access error.
Below is the code:
Code:
Private Sub cmdBrowse_Click()
On Error GoTo Err_Handler
Dim PathStrg As String
Dim relativePath As String
Dim dbPath As String
'Code compatible with both 32-bit & 64-bit Office
' Set options for the file dialog box.
Dim F As FileDialog
Set F = Application.FileDialog(msoFileDialogFilePicker)
F.Title = "Locate the image file folder and click on 'Open' to select it"
' Clear out any current filters, and add our own
F.Filters.Clear
F.Filters.Add "Image files", "*.jpg;*.jpeg"
' Set the start folder. Open in default file folder if blank
F.InitialFileName = Nz(Application.CurrentProject.Path & "\Images\", "C:\") 'modify this as appropriate
' Call the Open dialog procedure.
F.Show
' setup new file name and appropriate DB subfolder
relativePath = "\Images\" & Me.txtObjectID & ".jpg"
dbPath = Application.CurrentProject.Path
'copy selected file with new name and subfolder
FileCopy LCase(PathStrg), dbPath & relativePath
'update the table field with the new file name and relative location
Me!ImagePath.Value = relativePath
'display the image from the subfolder of the DB
Me.Requery
Exit_Handler:
Exit Sub
Err_Handler:
If Err <> 5 Then 'err=5 user cancelled
MsgBox "Error " & Err.Number & " in cmdBrowse_Click procedure: " & Err.Description
End If
Resume Exit_Handler
End Sub