pcalabria
asked on
Need help creating a continuous form that displays images in MS Access
We have a list of PartNumber and wish to create a continuous form that shows each part number and all the images we have for each.
Each part number may have up to five images are stored in our images directory that I will call strFullPath.
strFullPath="\\MyServer\MyFolder\Images\
We identify each image with a dash number starting with zero.
For Example:
When the PartNumber is 12345 the five images would be named
strFullPath & "12345-0.jpg"
strFullPath & "12345-1.jpg"
strFullPath & "12345-2.jpg"
strFullPath & "12345-3.jpg"
strFullPath & "12345-4.jpg"
One challenge is that not all part numbers have five images, in fact, some part numbers do not have any images at all.
I created a continuous form with a text box called PartNumber that is bound to the PartNumber field of my recordsource, and five unbound picture controls. The picture controls are named image0, image1, impage2, image3 and image4.
I added the following code to the oncurrent event of the form which does not work:
strImagePath = "\\MyServer\MyFolder\Images\" & Me.PartNumber
If Dir(strImagePath & "*.jpg") <> "" Then
strImage = Dir(strImagePath & "*.JPG")
strFullPath = strImagePath & strImage
Me.Image0.Picture = strFullPath
Me.Image0.HyperlinkAddress = strFullPath
End If
I didn't bother to write code for the other image controls as the code above does not work with the first image.
Can anyone help??
Each part number may have up to five images are stored in our images directory that I will call strFullPath.
strFullPath="\\MyServer\MyFolder\Images\
We identify each image with a dash number starting with zero.
For Example:
When the PartNumber is 12345 the five images would be named
strFullPath & "12345-0.jpg"
strFullPath & "12345-1.jpg"
strFullPath & "12345-2.jpg"
strFullPath & "12345-3.jpg"
strFullPath & "12345-4.jpg"
One challenge is that not all part numbers have five images, in fact, some part numbers do not have any images at all.
I created a continuous form with a text box called PartNumber that is bound to the PartNumber field of my recordsource, and five unbound picture controls. The picture controls are named image0, image1, impage2, image3 and image4.
I added the following code to the oncurrent event of the form which does not work:
strImagePath = "\\MyServer\MyFolder\Images\" & Me.PartNumber
If Dir(strImagePath & "*.jpg") <> "" Then
strImage = Dir(strImagePath & "*.JPG")
strFullPath = strImagePath & strImage
Me.Image0.Picture = strFullPath
Me.Image0.HyperlinkAddress = strFullPath
End If
I didn't bother to write code for the other image controls as the code above does not work with the first image.
Can anyone help??
ASKER
David.. where does this code go, in the form OnCurrent event?
Also, in your example, would strImage be an array with all the values or an object?
How would I dimension it?
Thanks
Also, in your example, would strImage be an array with all the values or an object?
How would I dimension it?
Thanks
Dim strimages As New Collection
strImages = Dir(strImagePath & "*.JPG")
Arrays are typically used when one knows how many
Collections when the size is unknown.
If Dir(strImagePath & '\' & PartNumber & "-0.jpg") <> "" Then
This returns only 1 item
strImages = Dir(strImagePath & "*.JPG")
Arrays are typically used when one knows how many
Collections when the size is unknown.
If Dir(strImagePath & '\' & PartNumber & "-0.jpg") <> "" Then
This returns only 1 item
ASKER
very good info.. I never used a collection before.. sure understand the value!!
but where does the code go?
in the oncurrent for the form?
remember this needs to be a continuous form
but where does the code go?
in the oncurrent for the form?
remember this needs to be a continuous form
wherever your controls are
I didn't bother to write code for the other image controls as the code above does not work with the first image.
I didn't bother to write code for the other image controls as the code above does not work with the first image.
ASKER
Dim strImages As New Collection
Dim strImagePath As String
strImagePath = "\\MyServer\MyFolder\Images\"
strImages = Dir(strImagePath & "*.JPG")
This is throwing an "Argument not optional" error when I try to compile.
Dim strImagePath As String
strImagePath = "\\MyServer\MyFolder\Images\"
strImages = Dir(strImagePath & "*.JPG")
This is throwing an "Argument not optional" error when I try to compile.
my sistacke confusing vb and vba
Dir returns the first file name that matches pathname. To get any additional file names that match pathname, call Dir again with no arguments. so it wil be a string and not a collection.
Dir returns the first file name that matches pathname. To get any additional file names that match pathname, call Dir again with no arguments. so it wil be a string and not a collection.
If you really want to display pictures in a continuous way then its either ListView or MsFlexGrid...
Pat,
You might want to consider using a 3rd party control. dbPix works extremely well. here's an example:
http://www.ammara.com/support/samples/access-master-detail-images-ex.html
and here's the main page link:
http://www.ammara.com/
Jim.
You might want to consider using a 3rd party control. dbPix works extremely well. here's an example:
http://www.ammara.com/support/samples/access-master-detail-images-ex.html
and here's the main page link:
http://www.ammara.com/
Jim.
ASKER
Thanks all.
I've struggled with continuous forms and displaying images for years...
I almost could not believe how simple this solution was... and it did not involve any third party or other components.
The problem has been that I've always tried to do so using FORMS.
I really hope this will help someone else in a similar situation...
The solution is... use a REPORT.
I created a query of 500,000 items in our inventory...which I used as my recordsource.
I added ten picture controls about 1 inch square.
I added links to ten images in a report using the picture control.. we call them -0,-1,2 etc
I added the same link to the hyperlink address.
Open the report!!! Presto...
Great performance... click on any image to go to full size.. use the zoom control to get as large as you like..
I can scroll through all images without delay.
Missing images do not display and do not throw errors...
I really wish I had thought of this sooner...
I've struggled with continuous forms and displaying images for years...
I almost could not believe how simple this solution was... and it did not involve any third party or other components.
The problem has been that I've always tried to do so using FORMS.
I really hope this will help someone else in a similar situation...
The solution is... use a REPORT.
I created a query of 500,000 items in our inventory...which I used as my recordsource.
I added ten picture controls about 1 inch square.
I added links to ten images in a report using the picture control.. we call them -0,-1,2 etc
I added the same link to the hyperlink address.
Open the report!!! Presto...
Great performance... click on any image to go to full size.. use the zoom control to get as large as you like..
I can scroll through all images without delay.
Missing images do not display and do not throw errors...
I really wish I had thought of this sooner...
Forms is not a report and a report is not a form.
Although reports have some added interaction functionality you can't for example click here and add a new product(well you can but the concept is not that straightfoward)
Although reports have some added interaction functionality you can't for example click here and add a new product(well you can but the concept is not that straightfoward)
You may be able to use the simple method described in my article:
Show pictures directly from URLs in Access forms and reports
Your path would be something like:
file:///\\server\path\YourPicture.png
It will cache the files locally which may or may not speed up things.
Show pictures directly from URLs in Access forms and reports
Your path would be something like:
file:///\\server\path\YourPicture.png
It will cache the files locally which may or may not speed up things.
ASKER
Thanks again everyone.. and thanks John and Gustav...
Using a report completely solved my problem.. the performance is excellent..
I created a report with 10 image controls, and added hyperlinks to the images..
The record source selects the records I want.. the form.. in continuous mode.. shows me all the images I want to see...
I display the image about inch and a half wide on the screen.. and use the hyperlink to the full image to go full size..
I can't image any solution that could be better..
I could not get this, however, to work with forms.
Using a report completely solved my problem.. the performance is excellent..
I created a report with 10 image controls, and added hyperlinks to the images..
The record source selects the records I want.. the form.. in continuous mode.. shows me all the images I want to see...
I display the image about inch and a half wide on the screen.. and use the hyperlink to the full image to go full size..
I can't image any solution that could be better..
I could not get this, however, to work with forms.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Download my demo from the article. It contains both forms and reports.
This will return a collection so you have to go through each element of the array using a foreach
https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/for-eachnext-statement