Adding filename to a separate text field when batch uploading images

Hi - I'm using this program DBPix and it's just great for what I need it to do.  I can upload a batch of photos or a single photo, depending on my needs.  My table for storing the images is pretty simple:

ItemID (autonumber)
ImgDetail (OLE Object)
DetailWidth (Number)
DetailHeight (Number)
ImgThumbnail (OLE Object)
ThumbWidth (Number)
ThumbHeight (Number)
ImgFileName (Text)

Below is the code for uploading the images (batch style).  The only thing I'd like to alter about it, is to take the filename (just the filename, not the path) and add that to the "ImgFileName" field on it's own.  I need to be able to use the filename for relationships down the road, so having this stored as text on its own would be extremely helpful.

Any help would be extremely appreciated!!!!

' Batch-Load button clicked: Load an entire folder of images (into new records)
Private Sub btnBatchLoad_Click()
    On Error GoTo Finish

    Dim strFile As String
    Dim strFullPath As String
    Dim strFolderName As String
   
    ' Display a 'Browse for folder' dialog - see 'BrowseForFolder' module
    strFolderName = BrowseFolder("Select folder to load images from")
   
    If Not IsEmpty(strFolderName) And Not strFolderName = "" Then
        strFile = Dir(strFolderName + "\" + "*.jpg", vbNormal)
   
        While (Not StrComp(strFile, ""))
            If Len(strFile) > 1 Then
                strFullPath = strFolderName + "\" + strFile
                DoCmd.GoToRecord , , acNewRec
                DBPixMain.ImageLoadFile (strFullPath)
            End If
            strFile = Dir
        Wend
    End If

Finish:

End Sub

ncalcaterraAsked:
Who is Participating?
 
ncalcaterraConnect With a Mentor Author Commented:
Capricorn/Helen - Thanks for your suggestions, I really appreciate it.  My issue is now resolved by taking the following action:

Replace the following line:
    DBPixMain.ImageLoadFile (strFullPath)
With this:
    If DBPixMain.ImageLoadFile (strFullPath) Then
        [ImgFileName] = strFile
    End If

So, the full batch-load code appears as:

' Batch-Load button clicked: Load an entire folder of images (into new records)
Private Sub btnBatchLoad_Click()
    On Error GoTo Finish

    Dim strFile As String
    Dim strFullPath As String
    Dim strFolderName As String
   
    ' Display a 'Browse for folder' dialog - see 'BrowseForFolder' module
    strFolderName = BrowseFolder("Select folder to load images from")
   
    If Not IsEmpty(strFolderName) And Not strFolderName = "" Then
        strFile = Dir(strFolderName + "\" + "*.jpg", vbNormal)
   
        While (Not StrComp(strFile, ""))
            If Len(strFile) > 1 Then
                strFullPath = strFolderName + "\" + strFile
                DoCmd.GoToRecord , , acNewRec
                    If DBPixMain.ImageLoadFile(strFullPath) Then
                        [ImgFileName] = strFile
                    End If

            End If
            strFile = Dir
        Wend
    End If

Finish:

End Sub
0
 
Rey Obrero (Capricorn1)Commented:
not sure if you can alter the codes for DBPixMain.ImageLoadFile, but perhaps you can derive it from the image record in the table..

so, if am not mistaken you are using a form bound to the table, is this correct?

lets  try this,
* create a table, name it tempTable with two fields tmpID Number, Imagename text
* load image name to the tempTable when you do a Batch load
* update the Image table after wards, using the records from tempTable
0
 
Helen FeddemaCommented:
Here is a function that extracts just the file name from the a full path variable:
Public Function SplitFileName(strFileAndPath) As String
'Created by Helen Feddema 4-Aug-2006
'Last modified 31-Jan-2010

On Error GoTo ErrorHandler

   Dim strFullPath() As String
   Dim intUBound As Integer
   
   'Extract file name from variable with file and path
   strFullPath = Split(strFileAndPath, "\", -1, vbTextCompare)
   intUBound = UBound(strFullPath)
   SplitFileName = strFullPath(intUBound)
   
ErrorHandlerExit:
   Exit Function

ErrorHandler:
   MsgBox "Error No: " & Err.Number & "; Description: " & Err.Description
   Resume ErrorHandlerExit

End Function

Open in new window

0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
Rey Obrero (Capricorn1)Commented:

the filename is already available from variable  strFile, so why need a function to extract the fileName
0
 
ncalcaterraAuthor Commented:
Thanks to you both - it sounds like you know what i'm trying to do.  here is what the data looks like in my table, once the image is uploaded:
ItemId, ImgDetail,  DetailWidth, DetailHeight, ImgThumbnail,  ThumbWidth, ThumbHeight, ImgFileName
1, Long Binary Data, 576,  432,  Long Binary Data, 176,  132,
2, Long Binary Data, 576,  432,  Long Binary Data, 176, 132,

Since it's storing it as "long binary data", i'm just wanna get that filename out of there and put it in a separate field ("ImgFileName").
Any new advice?
 
0
 
Rey Obrero (Capricorn1)Connect With a Mentor Commented:
ncalcaterra,

try to read again mu suggestion and post back here if you have any question.
0
 
ncalcaterraAuthor Commented:
Capricorn - I created tempTable as you suggested.  Can you show me in the code above how I populate this table with the imagename & tmpID when I'm doing a batch upload?  I will play around with this tonight and see if I have any luck.  Appreicate your help!
0
All Courses

From novice to tech pro — start learning today.