+ Reply to Thread
Results 1 to 42 of 42

Search an Excel Database and display results w/ pictures.

  1. #1
    Registered User
    Join Date
    05-28-2007
    Posts
    28

    Unhappy Search an Excel worksheet and display results w/ pictures.

    Hello,

    I have very little experience with programming, as a matter of fact the code in the sample file is the extent of my knowledge. I want to use Excel because not everyone in the plant has access to Access, but everyone has Excel.

    The idea is to allow searching for parts based on 2 different part numbers, category, drawer, manufacturer, or description (any or all).

    My first problem is how to make excel search using a userform and find multiple results, not just stopping after it finds the first match. For instance if you only searched for a category it should find all results that match that category.

    (I'll try to anticipate a question here: the part numbers should be unique but may not be, so using the part number as a key will not work.)

    The second thing is I would like to know how to populate these results in a listbox and and have the selected part show the matching picture. (This maybe more clear after seeing the spreadsheet).

    And finally, is there any way to make the comboboxes on the search userform populate themselves off of the list of data.

    I apologize if any of these questions have been answered already but frankly I've been searching google for the past week and haven't found anything, (This may attest to my search skills as well, ha ha ha), and I really just want this to be finished.

    Any and all help much appreciated!

    -L

    Sorry had an upload error with the file, should be OK now.
    Attached Files Attached Files
    Last edited by Schmoozer; 05-28-2007 at 06:38 PM.

  2. #2
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591
    Hi

    Have a look at the attached.

    1) I've only used the category as an example.
    2) Data sheet now has 4 entries for a category of test2.
    3) Category is loaded at the form initialization stage
    4) I've used an advanced filter to extract the relevant information
    5) The output is now a 7 column listbox, that shows the results of the filter.

    Open the form, select search for a part, then select test2 from the Category dropdown, press search and the relevant items should show up in the output form.

    Hope this gives you some ideas on how to proceed.


    rylo
    Attached Files Attached Files

  3. #3
    Registered User
    Join Date
    05-28-2007
    Posts
    28

    Thumbs up

    Wow, thanks Rylo!

    OK first, for the combo box

    Yours worked great, but when I tried to transfer it over to the original worksheet I don't get an error but the comboboxes are empty, any thoughts?

    Please Login or Register  to view this content.
    Last edited by Schmoozer; 05-28-2007 at 08:47 PM.

  4. #4
    Registered User
    Join Date
    05-28-2007
    Posts
    28

    Talking $$$

    Okay this really does need to be done tonite.

    So if anyone can have it working tonite I'll paypal you 20 dollars once i confirm it works at work tomorrow.

  5. #5
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591
    Hi

    The code needs to go into the form initialization event.
    Or are you calling the subs from there?


    rylo

  6. #6
    Registered User
    Join Date
    05-28-2007
    Posts
    28
    I'm not quite sure what you mean by that, so probably not...

  7. #7
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591
    Hi

    If you go back to my original code, you will see that the code to fill the combobox is in a sub called userform_initialize in the form_search code area. Basically, this is event code that will run when the form is loaded.

    So if you don't have the code there, then it is not being called.

    Do a bit of a test and put the code for the category combobox into the initialize area, and get that part working. Then expand for the rest.


    rylo

  8. #8
    Registered User
    Join Date
    05-28-2007
    Posts
    28

    Talking 1 down 2 to go....

    Rylo,

    1.
    I seem to have everything the same as yours however my listbox in search results does not seem to populate. Also by your earlier comments I got the impression that your search results are set to a maximum, x. Can, x, be automatically set to the number of occupied rows in the data worksheet.

    2.
    How can I have the search results omit the 'picture' column and actually try to pull the picture file up based on the file path?


    -L
    Attached Files Attached Files

  9. #9
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591
    Hi

    1) On the results sheet, I have a defined name called resultss that will dynamically adjust for the number of entries returned from the advanced filter. You will have to insert that into your file.

    You will then have to change the row source on your output listbox to refer to that name, change the column count to 7, the column widths to 60 and perhaps alter the headings to true.

    2) If you want to exclude the picture address, then you will have to change the output from the filter to exclude that item. Be careful if you just delete the column as it will impact the crtieria range. You will also have to adjust the number of columns in the listbox.


    rylo

  10. #10
    Registered User
    Join Date
    05-28-2007
    Posts
    28

    Question

    Hello,

    1) When I try to set the Row Source under properties for the list box to 'resultss' I get the error message: "Could not set the rowsource property. Invalid property value."

    2) If you want to exclude the picture address, then you will have to change the output from the filter to exclude that item. Be careful if you just delete the column as it will impact the crtieria range. You will also have to adjust the number of columns in the listbox.
    How do I change the "output from the filter"?

  11. #11
    Registered User
    Join Date
    05-28-2007
    Posts
    28

    Red face Almost there

    Ok scratch that last post.


    So how do I make the little picture box on the right side show the picture from the file path listed under 'picture' when I click an entry?
    Last edited by Schmoozer; 05-28-2007 at 11:08 PM.

  12. #12
    Registered User
    Join Date
    05-28-2007
    Posts
    28

    Talking Anyone???

    Ok i'll be awake for another hour and a half.

    Don't forget the 20 bucks folks!!!!!

  13. #13
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591
    Hi

    Assuming that results!C still contains the picture path name, then in the search_results code block insert the following code

    Please Login or Register  to view this content.
    When the listbox shows with the results, click on an entry and the picture should load.

    If you have removed the picture path from column C, then adjust the code accordingly.


    rylo

  14. #14
    Registered User
    Join Date
    05-28-2007
    Posts
    28

    Thumbs up

    Cool, a few little problems. The pictures are one off, ie 1 shows pic 2.

    Second if the file path doesn't exist it needs to have a msg box, as it is now it goes into debug mode.

    And third the pictures don't resize themselves.



    Any thoughts?




    Heres how it looks so far, (search for "u" under manufacturer)
    Attached Files Attached Files
    Last edited by Schmoozer; 05-29-2007 at 12:40 AM.

  15. #15
    Registered User
    Join Date
    05-28-2007
    Posts
    28

    Red face So close......................

    So close......................

  16. #16
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591
    Hi

    1) Change Search_Results.listbox1 columnheads to TRUE
    2) Ajust the defined name refers to formula to be:
    =OFFSET(Results!$A$2,0,0,COUNTA(Results!$A:$A),7)
    3) Change the listbox1 code to be
    Please Login or Register  to view this content.
    I'll have a fiddle with the resize issue.


    rylo

  17. #17
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591
    Hi

    Try changing the image1.picturesizemode to 1 (stretch). The help file explains that this may cause some distortion and I didn't try what would happen if the image is too large for the window.

    Try each of the options and evaluate the results to see which would be best for your situation. You may have to resize the picture window, or use a best for the most type arrangement.


    rylo

  18. #18
    Registered User
    Join Date
    05-28-2007
    Posts
    28
    I'm a little confused about "=OFFSET(Results!$A$2,0,0,COUNTA(Results!$A:$A),7)" where do I put it?

    And turning column heads on just adds Column A, B, C, D etc but doesn't get rid of the Hanel_No, Man_Man_No etc in the search results.
    Attached Files Attached Files

  19. #19
    Registered User
    Join Date
    05-28-2007
    Posts
    28
    No the strech seems to work perfetly, I'd really just like to get rid of both of those column headers, i thin that will fix the numbering proble ie #1 showing #2 picture

  20. #20
    Registered User
    Join Date
    05-28-2007
    Posts
    28
    Nevermind, the last thing that needs to be done is to get rid of the Header that was in the search results list box before setting the columnheader to true

  21. #21
    Registered User
    Join Date
    05-28-2007
    Posts
    28
    Just need to get rid of this and thats it!!!!!!!!!!
    Attached Images Attached Images

  22. #22
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591
    Hi

    If you have the defined name resultss starting from A2, then set listbox1.columnheadings to false and it should get rid of them.


    rylo

  23. #23
    Registered User
    Join Date
    05-28-2007
    Posts
    28
    When column heads was set to true it actually added another set of headings. How do i set the defined name resultss to start at A2?

  24. #24
    Registered User
    Join Date
    05-28-2007
    Posts
    28
    Hmmmmm it also doesn't seem to work when you have two fields with an input in the search userform:

    Please Login or Register  to view this content.

  25. #25
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591
    Hi

    Worked on the last example file you sent up. Category a, Manufacturer u brings up results....

    If you most recent file doesn't work, can you put it up with the parameters used to bring back no result.


    rylo

  26. #26
    Registered User
    Join Date
    05-28-2007
    Posts
    28

    Thumbs up OK almost everything is working.

    One big problem and then I think I can handle the rest of it.


    The picture file paths are generated by the =CONCATENATE function. So a particular part may not actually have a picture. In this event I would like it to default to a picture that displays "File Not Found" or fnf.bmp (located on Sheets: "data" and range: "I1".

    So heres what I have:

    Please Login or Register  to view this content.
    However instead of just displaying the fnf.bmp it comes up with a Run-time error "53": File not found. With end or debug as options.



    I tried playing around with error handling but couldn't get that to work either:

    Please Login or Register  to view this content.
    Thanks in advance!





    Rylo, thanks so much for taking the time to go through and start debugging the program. It was a big help.

  27. #27
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591
    Hi

    What is in

    Sheets("data").Range("I1")

    On the example file it is blank.

    If you have a path and the file is definitely in that location, then try changing it to

    Sheets("data").Range("I1").value and see if that loads


    rylo

  28. #28
    Registered User
    Join Date
    05-28-2007
    Posts
    28

    Lightbulb Maybe this will help clear some stuff up

    Maybe this will help clear some stuff up. I've actually been trying to figure this stuff out.


    One problem though: When I was trying to get rid of the column header in the listbox on the Search_Results form I messed something up and can't seem to fix it. But if you can fix that:

    Please Login or Register  to view this content.
    Then you should have the same problem with pictures that I'm having.



    Thanks Rylo!
    Attached Files Attached Files

  29. #29
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591
    Hi

    1) Change the code from

    Please Login or Register  to view this content.
    to

    Please Login or Register  to view this content.
    2) You will have to correct the formula for the defined name resultss to
    =OFFSET(Results!$A$2,0,0,COUNTA(Results!$A:$A),7)
    It currently has a #REF! error

    3) The default load picture details are in data!I2 not data!I1. Change that reference in the listbox1_click event.

    4) Also change the listbox1_click event to comment out the error handler, and bring back the loadpicture command.

    Things worked for me from there.


    rylo

  30. #30
    Registered User
    Join Date
    05-28-2007
    Posts
    28

    Arrow

    Quote Originally Posted by rylo
    2) You will have to correct the formula for the defined name resultss to
    =OFFSET(Results!$A$2,0,0,COUNTA(Results!$A:$A),7)
    It currently has a #REF! error

    I'm not sure what you mean by this.

    Sorry this is my second week working with VBA

  31. #31
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591
    Hi

    Go to sheet Results. Then go Insert, name, define and you will see that there is a name called resultss. Select the name, and bottom is a refers to: box that contains a formula. The formula currently contains a #REF!. This will have to be replaced as per the formula I gave you.

    This defined name is dynamic and will select the results of the filter. The form listbox refers to this defined name to obtain its data.


    rylo

  32. #32
    Registered User
    Join Date
    05-28-2007
    Posts
    28

    Ok....

    So I search for a part.

    Then I click on the part I want to see the picture of.

    Then I get this error message when the picture file path isn't correct.

    If you don't get the same message then I'm not sure whats happening....

    (Specifically any of the files with valid file paths work, files with no file paths work, but files with invalid file paths get the debug error.)

    (I hope that makes sense.)

    (If doesn't just tell me if #122 works for ya.)

    (oh and these may help (unzip the drive c zip in your c drive))
    Attached Images Attached Images
    Attached Files Attached Files
    Last edited by Schmoozer; 06-07-2007 at 08:19 PM.

  33. #33
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591
    Hi

    Try updating the code to

    Please Login or Register  to view this content.
    Wasn't thinking of a missing file / incorrect file path / name when looking at this, just the default file or existing file.


    rylo

  34. #34
    Registered User
    Join Date
    05-28-2007
    Posts
    28
    Yeah I probabally should of made that more clear.

    In anyevent at least the end/debug screen has stopped coming up.

    A shortcoming of the example I gave you is that the incorrect filepaths are not intermitten, they are all at the end. So on your example all the inccorrect file paths would show up with the fnf.bmp.

    However when I put the real data in what happens is when the file path isn't valid it just doesn't update the picture box. For instance if #3 file path was incorrect it would just show the #2 picture if you were scrolling down through the list. I hope that clear. Try deleteing on of the 3.bmp and you'll see what I mean.

    So I was thinking :
    Please Login or Register  to view this content.
    But that doesn't seem to work either.

    Thanks for the help Rylo!

  35. #35
    Registered User
    Join Date
    05-28-2007
    Posts
    28

    Cool

    And a second, much less important question then the one above. Why doesn't this work?

    Please Login or Register  to view this content.
    Its under the 'part_maintenance' code. What seems odd to me is that if you leave it blank it works, but all other entries recieve "incorrect password" message boxes, even correct passwords.

  36. #36
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591
    Hi

    1) Pictures:
    I think there is a workflow issue coming in here. Lets see if this is the correct order of events.
    a) A valid path and picture exists it is loaded.
    b) The path is a "-", then the default is loaded.
    c) An invalid path / picture as the first selection then .... what do you want to happen???
    d) An invalid path / picture is selected after either (a) or (b) have already been selected then ...... what do you want to happen.

    When you select an invalid item after selecting a valid one, the existing picture is not removed. This is where you have to specify any action. If you have other scenarios, then can you determine what you want to happen for each and every one.

    2) Your code seems to be missing a couple of things.
    (a) is p a global variable? If it is not, then setting it in Set_Password will not have any impact on the variable p in btnAddPart_Click
    (b) pa55w0rd is a variable, not a string. Again, is this global, and has it been set somewhere else. From the code below, pa55w0rd would be blank, and so p will be blank. Nothing will be carried over to the other sub.


    rylo

  37. #37
    Registered User
    Join Date
    05-28-2007
    Posts
    28

    Red face

    Hi,

    Picture:
    If the picture file path is valid load the picture. In all other instance load the defualt (assuming the defualt is the file not found picture). This includes after either a (after) or b (before) has already been loaded.

    So does that mean I need two more if/then/else stements?





    Password:
    Please Login or Register  to view this content.
    I think this is the right idea....

    But why if I call set_password do I need to have 'p' set a public variable. Won't this set it in each sub that it is called in.

    In any event my code still doesn't work. Any suggestions

  38. #38
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591
    Hi


    Picture: try

    Please Login or Register  to view this content.
    Password:

    Have a look at the help file on the scope of variables. Basically, a local variable can only be used within the sub it is set. So in your case p is set in set_password, but the moment that sub finishes, the variable p disappears. If p was global, then setting it in set_password would make it available for use in btnAddPart_Click. Same with the variable pa55w0rd. I can't see where that is being set, or the type of variable. If you mean that the password is actually the string "pa55w0rd", then you have to set it as a string
    Please Login or Register  to view this content.

    rylo

  39. #39
    Registered User
    Join Date
    05-28-2007
    Posts
    28

    Lightbulb Bubblesort

    Please Login or Register  to view this content.
    Is there anyway to do this without setting a limit on the "Dim ManArray(2 To 1800) As String". Right now if the worksheet data was to grow larger than 1800 rows the combo boxes would just stop. Can the array be made to make itself as large as the data?

    Or is there a more efficent way to do this?

  40. #40
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591
    Hi

    Have a look at the REDIM PRESERVE approach. Basically you have a counter, and every time you want to add a new record to the array, you increment the counter, and redim preserve the array using the new counter variable.

    Another approach would be to work out the number of rows of data, and use that to initialize the array.


    rylo

  41. #41
    Registered User
    Join Date
    05-28-2007
    Posts
    28
    Hmmmmmm it still takes a while to load the comboboxes when the database hits about 2500 rows and just plain stops working at 3000.

    I'd like this database to be expandable, is there another, perhaps more efficent way to sort the comboboxes?

  42. #42
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591
    Hi

    Create a sheet that is hidden. Copy the data that you want to put into the comboboxes to that sheet, then use the inbuilt sort functions to sort the data however you want. You could then either (a) build your unique array for the combobox or (b) use an advanced filter to extract the unique data to a specified range on that hidden sheet that can be used as the source of your comboboxes.


    HTH

    rylo

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1