Link to home
Start Free TrialLog in
Avatar of ncalcaterra
ncalcaterra

asked on

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

Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

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


the filename is already available from variable  strFile, so why need a function to extract the fileName
Avatar of ncalcaterra
ncalcaterra

ASKER

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?
 
SOLUTION
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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!
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial