Batch loading file names into a text field

A

Ant S

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
 
S

Stuart McCall

Ant S said:
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
 
A

Ant S

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
 
S

Stuart McCall

Ant S said:
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

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top