Re: Batch loading file names into a text field

Discussion in 'Microsoft Access Form Coding' started by Stuart McCall, Oct 31, 2010.

  1. "Ant S" <> wrote in message
    news:...
    >I am trying to develop a small Access application for a local camera club I
    >am a member of. Being a novice I am struggling a bit with the code if
    >anyone can point me in the right direction?
    >
    > The idea of the application is that you batch load all the jpg images from
    > a folder into a database table then view and score the images via a side
    > show form.
    >
    >
    > I have a form that uses a DBPix 2.02 ActiveX picture control to display
    > the images, I have added a control button to batch load all the images
    > (working fine) but I would also like to add the file name into a text
    > field "tbl_FileName" on the same form. I don't know where or what to
    > incorporate that will place the filename into a text field.
    >
    > This bit is working fine and is used to batch lode the images into the
    > BDPix202 image control.
    >
    > ' Batch-Load button clicked: Load an entire folder of images (into new
    > records)
    > Private Sub Cmd_LoadBatch_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
    > DBPix202.ImageLoadFile (strFullPath)
    > End If
    > strFile = Dir
    > Wend
    > End If
    >
    > Finish:
    >
    > End Sub
    >
    >
    > The code below, I found to get the file name but I can't get to work. I
    > am trying to (at the same time as above) place the file name into the
    > tbl_FileName field. I don't know where to put it or how to call it?
    >
    > Function GetFilenameFromPath(ByVal strPath As String) As String
    > ' Returns the rightmost characters of a string upto but not including the
    > rightmost '\'
    > ' e.g. 'c:\My Docs\PhotoName.Jpg' returns PhotoName.Jpg'
    >
    > If Right$(strPath, 1) <> "\" And Len(strPath) > 0 Then
    > GetFilenameFromPath = GetFilenameFromPath(Left$(strPath,
    > Len(strPath) - 1)) + Right$(strPath, 1)
    > End If
    > End Function
    >
    >
    > Any help much appreciated. Thanks


    A recursive function to get a filename from a path is overkill to say the
    least.
    Try this instead:

    Public Function GetFilenameFromPath(ByVal FullPath As String) As String
    ' Returns the filename only from a fully qualified path
    GetFilenameFromPath = Mid$(FullPath, InStrRev(FullPath, "\") + 1)
    End Function
     
    Stuart McCall, Oct 31, 2010
    #1
    1. Advertisements

  2. "Ant S" <> wrote in message
    news:...
    > Thanks Stuart.
    >
    > Sorry if I sound a bit dim but I am a complete novice when it comes to
    > code! Can you suggest (without being rude :)) where this should go within
    > the On click Batch Load button code or do I need to put it somewhere else?
    >
    > Thanks
    >
    >
    > "Stuart McCall" <> wrote in message
    > news:dPdzo.22400$2...
    >> "Ant S" <> wrote in message
    >> news:...
    >>>I am trying to develop a small Access application for a local camera club
    >>>I am a member of. Being a novice I am struggling a bit with the code if
    >>>anyone can point me in the right direction?
    >>>
    >>> The idea of the application is that you batch load all the jpg images
    >>> from a folder into a database table then view and score the images via a
    >>> side show form.
    >>>
    >>>
    >>> I have a form that uses a DBPix 2.02 ActiveX picture control to display
    >>> the images, I have added a control button to batch load all the images
    >>> (working fine) but I would also like to add the file name into a text
    >>> field "tbl_FileName" on the same form. I don't know where or what to
    >>> incorporate that will place the filename into a text field.
    >>>
    >>> This bit is working fine and is used to batch lode the images into the
    >>> BDPix202 image control.
    >>>
    >>> ' Batch-Load button clicked: Load an entire folder of images (into new
    >>> records)
    >>> Private Sub Cmd_LoadBatch_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
    >>> DBPix202.ImageLoadFile (strFullPath)
    >>> End If
    >>> strFile = Dir
    >>> Wend
    >>> End If
    >>>
    >>> Finish:
    >>>
    >>> End Sub
    >>>
    >>>
    >>> The code below, I found to get the file name but I can't get to work.
    >>> I am trying to (at the same time as above) place the file name into the
    >>> tbl_FileName field. I don't know where to put it or how to call it?
    >>>
    >>> Function GetFilenameFromPath(ByVal strPath As String) As String
    >>> ' Returns the rightmost characters of a string upto but not including
    >>> the rightmost '\'
    >>> ' e.g. 'c:\My Docs\PhotoName.Jpg' returns PhotoName.Jpg'
    >>>
    >>> If Right$(strPath, 1) <> "\" And Len(strPath) > 0 Then
    >>> GetFilenameFromPath = GetFilenameFromPath(Left$(strPath,
    >>> Len(strPath) - 1)) + Right$(strPath, 1)
    >>> End If
    >>> End Function
    >>>
    >>>
    >>> Any help much appreciated. Thanks

    >>
    >> A recursive function to get a filename from a path is overkill to say the
    >> least.
    >> Try this instead:
    >>
    >> Public Function GetFilenameFromPath(ByVal FullPath As String) As String
    >> ' Returns the filename only from a fully qualified path
    >> GetFilenameFromPath = Mid$(FullPath, InStrRev(FullPath, "\") + 1)
    >> End Function


    Looking more closely at your code, it seems you don't need that function at
    all. You already have the filename in the variable strFile. So all you need
    to do is assign that to your textbox before moving to the 'new record' and
    Access will store the value. I've modified a snippet to demonstrate:

    While (Not StrComp(strFile, ""))
    If Len(strFile) > 1 Then
    strFullPath = StrFolderName + "\" + strFile

    Me.tbl_FileName = strFile

    DoCmd.GoToRecord , , acNewRec
    DBPix202.ImageLoadFile (strFullPath)
    End If
    strFile = Dir
    Wend
     
    Stuart McCall, Oct 31, 2010
    #2
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Guest
    Replies:
    4
    Views:
    210
    Guest
    Mar 25, 2005
  2. Incolor
    Replies:
    0
    Views:
    784
    Incolor
    May 19, 2006
  3. Guest

    Update Text Field Based on Value in First Text Field

    Guest, Sep 25, 2006, in forum: Microsoft Access Form Coding
    Replies:
    13
    Views:
    245
    Roger Carlson
    Oct 9, 2006
  4. Frank

    Dividing one text field into several text fields.

    Frank, Dec 11, 2006, in forum: Microsoft Access Form Coding
    Replies:
    3
    Views:
    192
    Frank
    Dec 12, 2006
  5. Replies:
    1
    Views:
    183
Loading...

Share This Page