PC Review


Reply
Thread Tools Rate Thread

Re: Batch loading file names into a text field

 
 
Stuart McCall
Guest
Posts: n/a
 
      31st Oct 2010
"Ant S" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>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


 
Reply With Quote
 
 
 
 
Stuart McCall
Guest
Posts: n/a
 
      31st Oct 2010
"Ant S" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:dPdzo.22400$(E-Mail Removed)2...
>> "Ant S" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>>>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


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
File Names: List Long file Names from Database List of short file names Ben Microsoft VB .NET 4 6th May 2006 01:20 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:49 PM.