Page 1 of 2 12 LastLast
Results 1 to 15 of 25
  1. #1
    4 Star Lounger
    Join Date
    Jun 2001
    Location
    Sacramento, California, USA
    Posts
    491
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Populate Listbox (WIN2000-Acc97)

    I have only worked with Access for a couple of years, and believe what I want to do is doable, it's just that I lack the expertise to code it.

    Scenario:
    Users will have a folder on their "C" drive called Magazines. In this folder they have scanned the covers of the magazines into jpeg files and named them accordingly. They will continue to add to this folder daily or weekly.
    What I would like <img src=/S/crossfingers.gif border=0 alt=crossfingers width=17 height=16> is the following:

    1) A listbox on a form whose record source is the list of files in the Magazine folder.
    2) User clicks on the file name inside the listbox and, voila, the file opens with the scanned photo.
    My guess is that
    1) I need some sort of API call to get the list?
    2) Use hyperlinks to open the file?

    This is probably more complicated than I can imagine. I even believe something similar was addressed here in the lounge(if you can point to the thread(s) that would get me started.)

    I did try the MSKB, but ya know, if you don't punch in the right keywords........ I tried populate list box, and didn't get what I needed.

    As always, thank you for reading this and thanks for your direction.
    Michael Abrams

  2. #2
    2 Star Lounger
    Join Date
    Dec 2000
    Posts
    120
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Populate Listbox (WIN2000-Acc97)

    This really isn't too difficult. The function below is from the Access help files. All you have to do is insert a module into your database and paste the ListJPGs function into it. You will have to change "yourfolderpath" to reflect the actual path of your JPEG folder.

    Then in the "Row Source Type" property of the listbox put "ListJPGs".

    You can then add an image frame to your form and in the AfterUpdate event of your listbox a line of code to change the picture:

    Me!imageframename.Picture = "jpegFolderPath" & Me!ListboxName

    Each time you select a file from the listbox the image will be displayed in the image frame.

    '''''''''''''''''''''''''''''''''''''''''''''''''' ''
    Function ListJPGs(fld As Control, id As Variant, _
    row As Variant, col As Variant, _
    code As Variant) As Variant
    Static dbs(127) As String, Entries As Integer
    Dim ReturnVal As Variant
    ReturnVal = Null
    Select Case code
    Case acLBInitialize ' Initialize.
    Entries = 0
    dbs(Entries) = Dir("yourfolderpath*.jpg")
    Do Until dbs(Entries) = "" Or Entries >= 127
    Entries = Entries + 1
    dbs(Entries) = Dir
    Loop
    ReturnVal = Entries
    Case acLBOpen ' Open.
    ' Generate unique ID for control.
    ReturnVal = Timer
    Case acLBGetRowCount ' Get number of rows.
    ReturnVal = Entries
    Case acLBGetColumnCount ' Get number of columns.
    ReturnVal = 1
    Case acLBGetColumnWidth ' Column width.
    ' -1 forces use of default width.
    ReturnVal = -1
    Case acLBGetValue ' Get data.
    ReturnVal = dbs(row)
    Case acLBEnd ' End.
    Erase dbs
    End Select
    ListJPGs = ReturnVal
    End Function

  3. #3
    4 Star Lounger
    Join Date
    Jun 2001
    Location
    Sacramento, California, USA
    Posts
    491
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Populate Listbox (WIN2000-Acc97)

    You are AWESOME !!!!!!!!!!!!!!!!!!!!
    2 things -
    Under what topic in the Access Help files
    was this located?

    When I try to place an image contol on the form, the "Insert Picture" Dialog box pops up.
    I am using Access 97 if this makes a difference.
    (Or am I using the wrong image control?)

    cpod - Thank you SO much. I hope to return the favor someday.

    Michael Abrams

  4. #4
    2 Star Lounger
    Join Date
    Dec 2000
    Posts
    120
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Populate Listbox (WIN2000-Acc97)

    I was mistaken when I said Access help files. It's actually under "Row Source Type" in the Visual Basic help files.

    No, you have the right control. You have to choose an image file when you add the control. This is the image that will appear when you open the form, before you select anything from the listbox. You could create a blank JPEG file for this purpose.

  5. #5
    4 Star Lounger
    Join Date
    Jun 2001
    Location
    Sacramento, California, USA
    Posts
    491
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Populate Listbox (WIN2000-Acc97)

    <img src=/S/clapping.gif border=0 alt=clapping width=19 height=23>

    Thanks again cpod. Cyberspace is just amazing <img src=/S/joy.gif border=0 alt=joy width=23 height=23>

    Michael

  6. #6
    4 Star Lounger
    Join Date
    Feb 2001
    Location
    Richland, Washington, USA
    Posts
    407
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Populate Listbox (WIN2000-Acc97)

    That dialog box just provides a default path/filename for the Picture property. You end up changing this property (and the displayed picture) when the user selects a value in the list. In other words, it doesn't really matter what file you pick.

    You may want to initialize this property with the default listbox selection (e.g., the first one in the list) in the form's On Load event -- using the same code 'cpod' provided (or just call the listbox_AfterUpdate routine from the Form_Open event routine. That way the listbox and the image will be "synchronized" when the form is opened.

    Hope this helps.

  7. #7
    4 Star Lounger
    Join Date
    Jun 2001
    Location
    Sacramento, California, USA
    Posts
    491
    Thanks
    0
    Thanked 0 Times in 0 Posts

    It's never easy !!

    OK. I created the module.
    Placed a listbox on the form.
    Rowsource Type = ListJPGS

    Open the form, and the 3 jpegs are listed in the list box.
    So far - wonderful.

    I placed an image control on the form. I used one of the files in the magazine folder as the default.
    I open the form and the image is there but the list box is now blank!!!
    I deleted the image control, compacted the db and the listbox is still blank.
    I closed the db and reopened it, and the listbox is populated again. What am I missing?

    Help !!! <img src=/S/nuts.gif border=0 alt=nuts width=15 height=15>

    Michael

    Couple of more facts - I am using Windows 2000

    The folder is located at;
    Cocuments and SettingsabramsmMy DocumentsMagazines

    In the code you gave me, all I put is dbs(Entries) = Dir("Magazines*.jpg")
    and it worked.
    It didn't work if I used:
    dbs(Entries) = Dir("Documents and SettingsabramsmMy DocumentsMagazines*.jpg")

  8. #8
    2 Star Lounger
    Join Date
    Dec 2000
    Posts
    120
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: It's never easy !!

    Try putting the drive letter in:

    Dir("Cocuments and SettingsabramsmMy DocumentsMagazines*.jpg")

  9. #9
    4 Star Lounger
    Join Date
    Jun 2001
    Location
    Sacramento, California, USA
    Posts
    491
    Thanks
    0
    Thanked 0 Times in 0 Posts

    OUTSTANDING

    I can now go home for the day !!! <img src=/S/flee.gif border=0 alt=flee width=25 height=25>

    THANK YOU VERY MUCH!!

    <img src=/S/clapping.gif border=0 alt=clapping width=19 height=23> <img src=/S/fanfare.gif border=0 alt=fanfare width=31 height=23> <img src=/S/groovin.gif border=0 alt=groovin width=21 height=21> <img src=/S/joy.gif border=0 alt=joy width=23 height=23>

  10. #10
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: OUTSTANDING

    I am using A2000 and have implemented this code and procedure for exactly the same procedure.
    My list box fills with the JPG names from my designated folder, all ok.

    When I click in the list box though, I get run-time 438 error.
    I've had this prob before in other forms and stuff and been able to fix it.

    However, I cannot find the problem in this instance. I presume it is the difference in A97 & A2000.

    How can I remedy this 438 fault.

    Dave

  11. #11
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: OUTSTANDING

    Dave,

    I don't have A2000, so I can't really help you here. Error 438 is "Property or method not supported", so you might be using the wrong kind of control. The image control on your form should be just that - an unbound image control, not one of the OLE controls - Object Frame or Bound Object Frame. See the attached screenshot of the relevant part of the Toolbox.

    Regards,
    Hans
    Attached Images Attached Images

  12. #12
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: OUTSTANDING

    Thanks for that, Perfect

    Dave

  13. #13
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: OUTSTANDING

    If KeyCode = vbKeyReturn Then
    DoCmd.GoToRecord , , acNewRec
    Me.EstimateNo = Forms!frmdetails!EstimateNo
    Me.supp = Forms!frmdetails!supp
    Me.txtRegistration = Forms!frmdetails!Registration
    Me.PicFile = Me.lstPreviewJpgs
    Me.[imgPicture].Picture = [PicFile]
    Me.lstPreviewJpgs.SetFocus

    I use this on keydown with the list.

    The problem is [PicFile] is a field on my form and requires the full path to allow [imgPicture] to work correctly.

    At the moment lstPreviewJpgs will return (example) 123.jpg to [picfile] instead of L:Home123.jpg

    Can any-one help with this.

    Dave
    Attached Files Attached Files

  14. #14
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: OUTSTANDING

    If all jpg's are stored in L:Home, try

    Me.[imgPicture].Picture = "L:Home" & [PicFile]

    If you have the pathname stored in a control or variable, you can use that instead of the literal string "L:Home". Don't forget to add a trailing backslash if necessary.

  15. #15
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: OUTSTANDING

    Slightly different but it now works


    If KeyCode = vbKeyReturn Then
    DoCmd.GoToRecord , , acNewRec
    Me.EstimateNo = Forms!frmdetails!EstimateNo
    Me.supp = Forms!frmdetails!supp
    Me.txtRegistration = Forms!frmdetails!Registration
    Me.PicFile = "L:Home" & Me.lstPreviewJpgs
    'Me.PicFile = Me.lstPreviewJpgs

    Me.[imgPicture].Picture = [PicFile]
    DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
    Forms!frmImages.SetFocus
    Forms!frmImages.lstPreviewJpgs.SetFocus
    Else

    Thanks.
    Dave

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •