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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
Rey Obrero (Capricorn1)Commented:

the filename is already available from variable  strFile, so why need a function to extract the fileName
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

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)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
ncalcaterraAuthor 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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.