Control source of a form field (1 Viewer)

wasim_sono

Registered User.
Local time
Tomorrow, 02:31
Joined
May 29, 2008
Messages
33
I have thousands of pictures in a folder. I want to display these pictures on a form. I used a blank continuous form having a field. whenever a user entered a number in this field form display the related picture.

I used following as control source of the field.
Code:
=("\\10.3.3.128\meter_pictures\" & [Forms].[Meter Enquiry].[meter_no] & ".jpg")

Its working, but I need to use "Like" operator to search more than one picture having similar number entered user on form.Each picture has a unique name consisting on starting 8 digit characters.
 

HiTechCoach

Well-known member
Local time
Today, 17:31
Joined
Mar 6, 2006
Messages
4,357
The built-in Access Image control require the exat path to a single image. It is not able to display multiple images. Which is why yu can use a wildcard.

What I do in may my applications is use VBA code to read the file names from the directory. I add them to a temp/work tbale that has a field for the file name and another for the full path (to be bound tot eh image control). Now you can use a form in continuous view to display all the images you want to load into the temp/work table.

You could:
1) load all the images first then search
2) ask for some search criteria and then load only the matching images.

Depending on the network speed, then second methnd might be faster.
 

wasim_sono

Registered User.
Local time
Tomorrow, 02:31
Joined
May 29, 2008
Messages
33
Thank you, HiTechCoach for your valuable comments. Kindly if possible then tell about the VBA code to use images.
 

static

Registered User.
Local time
Today, 23:31
Joined
Nov 2, 2015
Messages
823
If you are only displaying images you don't need to write anything to a table, just add them to a listbox.

Code:
'CONTROLS
'imgViewer -Image
'lstFiles -ListBox
'txtFolder -TextBox
'txtFilter - textbox for filter string

Const IMGTYPES As String = ".bmp,.dib,.jpg,.jpeg,.jpe,.jfif,.png,.gif,.tiff,.tif,"

Private Sub Form_Open(Cancel As Integer)
    lstFiles.RowSourceType = "value list"
    txtFolder_AfterUpdate
End Sub

Private Sub txtFolder_AfterUpdate()
    lstFiles = -1
    lstFiles.RowSource = ""
    imgViewer.Picture = ""
    If txtFolder = "" Then Exit Sub
    With CreateObject("Scripting.FileSystemObject")
        If .folderexists("" & txtFolder) Then
            For Each itm In .getfolder(txtFolder).files
                i = InStrRev(itm, ".")
                If i Then
                    typ = Mid(itm, i)
                    If InStr(IMGTYPES, typ) Then
                        If txtFilter <> "" Then
                            If InStr(itm.Name, txtFilter) Then _
                                lstFiles.AddItem itm.Name
                        Else
                            lstFiles.AddItem itm.Name
                        End If
                    End If
                End If
            Next
        End If
    End With
End Sub

Private Sub txtFilter_AfterUpdate()
    txtFolder_AfterUpdate
End Sub

Private Sub lstFiles_Click()
    p = txtFolder
    If p = "" Then Exit Sub
    If Right(p, 1) <> "\" Then p = txtFolder & "\"
    imgViewer.Picture = p & lstFiles
End Sub
 

HiTechCoach

Well-known member
Local time
Today, 17:31
Joined
Mar 6, 2006
Messages
4,357
Using static's suggestion of loading the image list into a listbox would allow you to bind an image control to the listbox. The user could click on am item in the listbox to show it.

The reason I suggested a table was it give you more flexibility. The table can be used as the rowsource for the listbox. This would also make filtering the list much easier without have to reload the listbox.

The main advantage to a table is the you can use it as the record source for a continuous form and display all the images on the form at once.

There are multiple was to do what you want. That is why it is good that you get lots of options.

It all comes to which methods works best for the User Interface you want to create.
 

Users who are viewing this thread

Top Bottom