Closed Thread
Results 1 to 21 of 21

Search through database and display results in userform

  1. #1
    Registered User
    Join Date
    12-20-2008
    Location
    Mumbai
    MS-Off Ver
    Microsoft Office 2003 and 2007
    Posts
    36

    Search through database and display results in userform

    I have a database of 13 columns and ever increasing rows.
    I want the following to be there on my userform.


    1 combobox:
    showing the list of categories from which to search.(The categories are the column headings in columns A1 to A13.The user will have to select one category.

    1 textbox:
    Here the user will enter the search term.

    1 Command Button:
    When the command button is clicked/entered, the code shall be such that it will search in the column corresponding to the category mentioned in the combobox and display the results( The entire 1 row x 13 cloumns containing the search term) in a Listbox. If the search term does not matches then a message box should appear with the message "No entries found"
    [B]


    1 Listbox:to display the search result as mentioned above.

    Thanks in advance for the help
    Last edited by karthikcoep; 01-29-2009 at 02:45 AM. Reason: Solved

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello karthikcoep,

    You can copy your data onto "Sheet1" of the attached workbook. Since it searches the active sheet, no need to worry about changing the sheet name. All 13 columns are visible in the ComboBox and the ListBox. I enhanced the search features to include matching by case or ignoring case, match the whole word or only part, and do a single search or search for all matches. The UserForm also acts like a standard window. You can minimize and maximize it to and from the task bar. Let me know how this works for you.

    Sincerely,
    Leith Ross
    Attached Files Attached Files

  3. #3
    Forum Expert MickG's Avatar
    Join Date
    11-23-2007
    Location
    Banbury,Oxfordshire
    Posts
    2,650
    Hi, I can't compete with Leith , but attached is a Simpler Version.
    Replace the test Data with your Data and also the column Headings (If there not too long !).
    Leith, Have you got a good starting point for API Calls ??
    Regards Mick
    Attached Files Attached Files

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    See the database form example

    http://www.excel-it.com/vba_examples.htm
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  5. #5
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello karthikcoep,

    If you really don't need all the bells and whistles of a UserForm to find, replace, add, and delete entries, here is simple and direct macro that will launch Excel's built-in database editor.
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

  6. #6
    Registered User
    Join Date
    12-20-2008
    Location
    Mumbai
    MS-Off Ver
    Microsoft Office 2003 and 2007
    Posts
    36

    Thank to everyone

    Hey thanks to everyone.Sorry for the late reply.
    @Leith: The file works well.

  7. #7
    Registered User
    Join Date
    12-20-2008
    Location
    Mumbai
    MS-Off Ver
    Microsoft Office 2003 and 2007
    Posts
    36

    Sorry need some change

    Hi Leith;
    Your form works pretty well.
    But I need it modifed.
    I have tried a lot but not able to do so.
    I want only the following.
    User selects a criteria from the combobox(Column 1 ro 13, Row 1)
    User types text in search field and then hits the search button
    In the list box all the results are listed. For each result there is only one single row.
    The top row of the listbox displays the 1row of the sheet.(That I can do)
    The results are displayed one below the other. So that the user need not use "prev" and "next".
    And the most important is when there are no results,a message box must pop up saying "No Results found".
    Thanks

  8. #8
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello karthikcoep,

    I have redone the UserForm. The ListBox has been replaced with a ListView control. The ListBox had to many limitations to do what you wanted. The version of this control works with Excel 2000 and up. If you plan to run this on earlier systems then some changes will have to be made to load the correct control. The searches are not case sensitive and match whole words only. All matches appear in the ListView with the row number and the values for columns "A" to "M".

    Sincerely,
    Leith Ross
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    12-20-2008
    Location
    Mumbai
    MS-Off Ver
    Microsoft Office 2003 and 2007
    Posts
    36

    Need this for a particular sheet

    Hey Thanks a lot Leith: This works like charm except that I have 4 sheets in my workbook.
    Out of that only one sheet contains the data that i need to search.
    So I tried
    Sheets(1).Select
    But it is not working
    Can u suggest how to use ur file if there are multiple sheets.

  10. #10
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello karthikcoep,

    I have made the changes to the attached workbook to search only the worksheet pointed to by Sheets(1).

    Sincerely,
    Leith Ross
    Attached Files Attached Files

  11. #11
    Registered User
    Join Date
    12-20-2008
    Location
    Mumbai
    MS-Off Ver
    Microsoft Office 2003 and 2007
    Posts
    36

    NOt working

    Hello Leith,
    The file u sent is running fine,
    but when i export the userform and import it back to use in my file it is not working. The gridlines are not visible.There is not error but in the listview control only the row no is displayed and nothing else.
    Please help.
    I tried this on a blank workbook then also it is not working.

  12. #12
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello karthikcoep,

    The problem is the reference library isn't loaded on the other machines. The workbook I posted has the reference saved. I have added a macro that will automatically load the library reference when the workbook is opened. Here is the auto loading macro which is called by the Workbook_Open() event procedure. This macro is located in Module1.
    Please Login or Register  to view this content.
    Workbook Open Event - ThisWorkbook Module
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross
    Attached Files Attached Files

  13. #13
    Registered User
    Join Date
    12-20-2008
    Location
    Mumbai
    MS-Off Ver
    Microsoft Office 2003 and 2007
    Posts
    36

    Re: Search through database and display results in userform

    Thanks a lot Leith.
    May god bless u!!!!!!!!!!!!!

  14. #14
    Forum Contributor
    Join Date
    06-20-2007
    Location
    Buckeye, AZ
    MS-Off Ver
    365
    Posts
    272

    Re: Search through database and display results in userform

    Leith,
    you've come sooo close to solving an project that has stumped me for weeks!
    in my woorksheet (see attached) i'm trying to search list (M) and chose from search list to return to cell D5. "D5:D55" will have this ability. Can you take me this last step?
    thank you,
    sick
    Attached Files Attached Files

  15. #15
    Registered User
    Join Date
    07-07-2010
    Location
    Montana, USA
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Search through database and display results in userform

    Hello Leith Ross, I found the program you wrote absolutly useful to a project that I am working on right now that has over 2500 product. I am wondering though, is there a way to change the code slighly to select the condensed data in the user box, and have it return to the worksheet highlighted. The only reason I would as Is that I would use a similar program so that the user could get to that row to access pdf forms that are embeded in each row? Any ensight would be lovely.

  16. #16
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Search through database and display results in userform

    Hello dmanatee,

    Please start a new thread. You can include the URL of this post as a reference.

    Your post does not comply with Rule 2 of our Forum RULES. Don't post a question in the thread of another member -- start your own thread. If you feel it's particularly relevant, provide a link to the other thread.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  17. #17
    Registered User
    Join Date
    08-18-2011
    Location
    KL, Malaysia
    MS-Off Ver
    Excel 2003
    Posts
    1

    Search & Display records on userform

    Hi I am very new to Excel/VBA. I have created a "JV INFORMATION SYSTEM" in excel and have designed a user form for users to enter new JV iNFO.

    My next step is to design a Search or find form for viewing the JV Information where
    user can choose to look up for JV info either by Company Name or Project Name or Date

    The worksheet that stored my data is called "JV" . In the sheet "JV " I have following 10columns

    Column A -No
    Column B-Company Name
    Column C Project Name
    Column D- Start Date
    Column E- End Date
    Column F- Equity Ratio
    Column G- Company Address
    Column H-Contact Person
    Column I-Contact No

    I did see a few examples of look up forms but am struggling to customise them to suit me.

    Ideally I need a combobox & textbox in search field. So user can choose the "Search by" category using combobox e.g. Company Name or Project Name or Date
    and then enter the relevent text in the textbox to carryout the search.

    and then use labels & listbox to display the related fields on the form. The reason I prefer labels is that I do not want users to edit the info. and listbox to show multiple results out of which user can choose specific one....e.g. when user does a search by Company, I want listbox to show the various Information about that company or when user search by date e.2 by Year , all information related to that year is display in the list box .

    any help would be appreciated...thx in advance

  18. #18
    Registered User
    Join Date
    10-11-2011
    Location
    dubai
    MS-Off Ver
    Excel 2007
    Posts
    1

    Re: Search through database and display results in userform

    we have 300 employee's details in sheet 1 (passport details / visa details/ labour details/ personal details/ salary details/ leave details) in sheet 2 need user form if i enter emp id then i have to get all details of emp. in sheet 2

  19. #19
    Forum Expert
    Join Date
    12-23-2006
    Location
    germany
    MS-Off Ver
    XL2003 / 2007 / 2010
    Posts
    6,326

    Re: Search through database and display results in userform

    Your post does not comply with Rule 2 of our Forum RULES. Don't post a question in the thread of another member -- start your own thread. If you feel it's particularly relevant, provide a link to the other thread.

  20. #20
    Registered User
    Join Date
    05-23-2012
    Location
    taguig
    MS-Off Ver
    Excel 2010
    Posts
    1

    Re: Search through database and display results in userform

    is it possible that the searched item can be link to a file? i want to link the search item directly to the file.

  21. #21
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Search through database and display results in userform

    Gkaty28,

    Welcome to the Forum, unfortunately:

    Your post does not comply with Rule 2 of our Forum RULES. Don't post a question in the thread of another member -- start your own thread. If you feel it's particularly relevant, provide a link to the other thread. It makes sense to have a new thread for your question because a thread with numerous replies can be off putting & difficult to pick out relevant replies.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

Closed 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