Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Advance VBA Code - need some assistance

Status
Not open for further replies.

macca007

Programmer
May 1, 2004
86
0
0
GB
Hi all,

I have this code which looks into the path of the folder of images and loads the images (one big image and the other a thumbnail).

My question is, How do i get the filename from the file? (i have higlighted the code in red where i would like to store the filename)

The code is this

' retrieve the path where images are stored - in this case the it's the path of the .mdb file itself
Dim Path As String
Dim FileName As String

Path = GetImgFolder

DBPixThumb.Image = Null
DBPixMain.Image = Null

FileName = Me!ItemId & ".jpg"
If Dir(Path & FileName) <> vbNullString Then
DBPixMain.ImageViewFile (Path & FileName)
End If

FileName = "t" & Me!ItemId & ".jpg"
If Dir(Path & FileName) <> vbNullString Then
DBPixThumb.ImageViewFile (Path & FileName)
End If

End Sub

Private Sub DBPixMain_ImageModified()
Dim FileName As String

DBPixThumb.Image = Null ' Clear the thumbnail
Me("ThumbWidth") = 0 ' Reset image info (and force update of Id if new record)
Me("ThumbHeight") = 0
Me("DetailWidth") = 0
Me("DetailHeight") = 0
'
If DBPixMain.ImageBytes > 0 Then
' Update the thumbnail
DBPixThumb.ImageLoadBlob (DBPixMain.Image) ' Copy/Paste is faster, if you don't mind overwriting the clipboard
' DBPixMain.ImageCopy
' DBPixThumb.ImagePaste
''
If DBPixMain.ImageSaveFile(GetImgFolder & Me!ItemId & ".jpg") Then
Me("hospno") = FileName

' Me("DetailWidth") = DBPixMain.ImageWidth ' Uppdate Detail image info
' Me("DetailHeight") = DBPixMain.ImageHeight
'
If DBPixThumb.ImageSaveFile(GetImgFolder & "t" & Me!ItemId & ".jpg") Then
' Me("ThumbWidth") = DBPixThumb.ImageWidth ' Update the thumbnail image info
' Me("ThumbHeight") = DBPixThumb.ImageHeight
End If
End If
End If
End Sub

Private Sub btnBatchLoad_Click()
On Error GoTo Finish

Dim strFullPath As String
Dim strFolderName As String
Dim i As Integer

' Display a 'Browse for folder' dialog - see 'BrowseForFolder' module
' strFolderName = BrowseFolder("Select folder to load images from")
strFolderName = "C:\Database\Images\"

If Not IsEmpty(strFolderName) And Not strFolderName = "" Then
Dim FileList As New Collection ' List of files in folder (to prevent potential recursive calls to Dir)
Dim strFile As String

strFile = Dir(strFolderName + "\" + "*.jpg", vbNormal)
Do While strFile <> ""
FileList.Add strFile
strFile = Dir
Loop

For i = 1 To FileList.Count ' Try to load each file - DBPixMain_ImageModified does the work of updating
strFile = FileList(i)
If Len(strFile) > 1 Then
strFullPath = strFolderName + "\" + strFile
DBPixMain.ImageLoadFile (strFullPath)
DoCmd.GoToRecord , , acNewRec
End If
Next i
End If

Finish:

End Sub


many thanks
 
You want this ?
Me("hospno") = Me!ItemId & ".jpg"

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Thanks PHV for reply,

Me!ItemId & ".jpg"

that just gives me itemID which is an autonumber that has been used in the folder. So each image has a unique id. What i would like to retrieve is the actual filenames for the hospno.

for example in folder images, there would be 3 images and there filenames would be :dx2222,dy3257,dc2834 etc

tblExternal

ItemID hospno
10 dx2222
11 dy3257
12 dc2834
13 dm2394

The code uses a module called getImageFolder that might help.

Public Function GetImgFolder() As String
Dim DBFullPath As String
Dim i As Integer

DBFullPath = CurrentDb().Name

' Strip the filename from the full path
For i = 1 To Len(DBFullPath)
If Mid(DBFullPath, i, 1) = "\" Then
GetImgFolder = Left(DBFullPath, i) & "Images\"
End If
Next
End Function

I hope i explained this well. If not i will try to clarify it abit more.

many thanks
 
Something like this ?
Me("hospno") = DLookUp("hospno", "tblExternal", "ItemID=" & Me!ItemId)

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top