none
make a form that show all images from a folder by cratyrea RRS feed

  • Question

  • hi:

    i have to build a form that show images 

    exempel i need to show all students images from class a or class b and etc'

     

    Wednesday, June 21, 2017 11:06 PM

All replies

  • Hi, You should be able to assign the file path to the Control Source of the image control. Hope it helps...
    Wednesday, June 21, 2017 11:11 PM
  • Hi, You should be able to assign the file path to the Control Source of the image control. Hope it helps...

    thanks

    i need it to it automatically base on the names in the table and query

    so if i open form"class a" it well fill at  automatically 

    Wednesday, June 21, 2017 11:18 PM
  • Will I get an answer :(
    Thursday, June 22, 2017 7:33 PM
  • Hi,

    Sorry for the delay... If you want to use a query or table, then assign the name of the field or column in the Control Source property of the image control.

    Hope it helps...

    Thursday, June 22, 2017 8:11 PM
  • For the layout you want you should use a report/subreport not a form.  You might like to take a look at Images.zip in my public databases folder at:

    https://onedrive.live.com/?cid=44CC60D7FEA42912&id=44CC60D7FEA42912!169

    Note that if you are using an earlier version of Access you might find that the colour of some form objects such as buttons shows incorrectly and you will need to  amend the form design accordingly.  

    If you have difficulty opening the link copy its text (NB, not the link location) and paste it into your browser's address bar.

    If you take a look at the Images.accdb file from the zip archive you'll see that this includes a button on the form to show multiple images of the person in question, selected in a list box, in a report/subreport in print preview.  In your case it would be a relatively simple task to create a similar form based on a Classes table, in which you could include a similar list box which references the ClassID primary key of the form.  You could then create a report/subreport similar to mine, but which returns multiple images per class rather than per person.

    For data input, you would use a form based on a Students table, however, similar to my contacts form.  You could then assign an image to each student in the same way that my form assigns images to a contact.  In your case you'd presumably assign only one image per student.

    When you open the Classes form it would then list all images for the students in the current class, and you could select all (using Shift+Click) to select the whole class, or you could select a subset of the students in the class, and preview or print the report.

    In all of the files in my demo the images are stored as external image files, with only the paths being stored as text values in the database.  The images are loaded into an Image control at runtime.  One thing to be aware of is that, with the very large image files produced by modern digital cameras, loading the images can be a little slow.  It is better, therefore, to use reduced resolution image files which are of adequate quality for display in the database or for printing in the report.

    Ken Sheridan, Stafford, England



    • Edited by Ken Sheridan Thursday, June 22, 2017 10:04 PM Typo corrected.
    Thursday, June 22, 2017 9:59 PM
  • thanks

    i'll try it

    Friday, June 23, 2017 10:46 AM
  • Hello,

    If your issue has been resolved, I suggest you mark helpful post or share your solution here to close this thread. If you issue persists, please let me know.

    If you have any new issues, please feel free to post new threads.

    Regards,

    Celeste


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, June 26, 2017 8:24 AM
    Moderator
  • Hi eshay1,

    you had mentioned that,"i have to build a form that show images".

    first the issue is you don't know that how many students are there in any particular class.

    so you can't add the image control at design time.

    so you can try to first count the file in folder. (here I assume that you had different folder for each class)

    for that you can use code below.

    Sub demo()
    
        Dim FolderPath As String, path As String, count As Integer
        FolderPath = "C:\Documents and Settings\demo\Desktop"
    
        path = FolderPath & "\*.bmp"
    
        Filename = Dir(path)
    
        Do While Filename <> ""
           count = count + 1
            Filename = Dir()
        Loop
    
       
        MsgBox count & " : files found in folder"
    End Sub

    so you will come to know that how many controls you need to add in form.

    now you can use code below to add controls dynamically with VBA code.

    Sub demo()
        Const strForm = "Form39"
        Const strCtl = "imgctrl1"
        Dim frm As Form
        Dim ctl As Control
        DoCmd.OpenForm FormName:=strForm, View:=acDesign
        Set frm = Forms(strForm)
        Set ctl = CreateControl(FormName:=strForm, ControlType:=acImage, _
            Left:=1440, Top:=2160, Width:=2880, Height:=288)
        ctl.Name = strCtl
        RunCommand acCmdFormView
        Forms(strForm).Controls(strCtl).Picture = "C:\Users\v-padee\Desktop\myimg\demoimg.bmp"
    End Sub
    
    

    Note that this is just to add 1 image. so you need to modify the code and place it in a loop and run the loop for the number of total file contains by the folder.

    loop through all the files and assign the file path to each new image control.

    so in loop , you need to create a image control first and then you need to assign image to it.

    to loop through file you can use code below.

    Sub demo()
        Dim MyObj As Object, MySource As Object, file As Variant
       file = Dir("c:\testfolder\")
       While (file <> "")
          If InStr(file, "*.bmp") > 0 Then
             MsgBox "found " & file
             Exit Sub
          End If
         file = Dir
      Wend
    End Sub

    you need to merge all the code example mentioned above to make it work.

    then when some one close the form at that time you also need to make form empty.

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, June 30, 2017 9:58 AM
    Moderator