+ Reply to Thread
Results 1 to 21 of 21

Search and display a record on a userform

  1. #1
    Registered User
    Join Date
    09-15-2014
    Location
    QLD Australia
    MS-Off Ver
    2010
    Posts
    18

    Post Search and display a record on a userform

    Hi everyone, back again.

    I have been steadily working on my project, and the next stage I was looking to implement a search and display function.
    The document is a register of businesses, which is usually well into the 100's in terms of number of records, so I wanted a nice and easy search function where someone can type any key word and it will pull up all the associated records - eg. 15 records found, and be able to cycle through them or select one to display in full based on name, owner, and Ref number.

    It needs to be displayed in a user-form type output so that the information can be easily be summarised for the user, I don't want them messing about with any of the data in table, even if it's just looking. The existing excel document which has been in use by myself and a few others was pretty much destroyed because people were entering and modifying data willy-nilly, so I am doing this redesign with userforms and macros to make it easy for those who are less proficient with technology (and so that they don't destroy any formatting or mess up entries).

    A copy of the document is attached for your perusal. Links to useful resources and other threads are also appreciated. I want to be able to understand the code and not just have things done for me.
    Attached Files Attached Files

  2. #2
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Search and display a record on a userform

    Hi, nice challenge.
    I'll pick this up later today and see if I can help, got some sample code with similar actions.
    I haven't looked at the file yet but what information would like to see in a summary list of the selection?
    I imagine you also want an extra button so show the entire record too of the selected item?
    ---
    Hans
    "IT" Always crosses your path!
    May the (vba) code be with you... if it isn't; start debugging!
    If you like my answer, Click the * below to say thank-you

  3. #3
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: Search and display a record on a userform

    https://www.excelforum.com/excel-pro...-userform.html
    The file in Post#4 will give you an idea on how to proceed.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  4. #4
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Search and display a record on a userform

    Your table a has 70 columns named Column99
    Is this intentional or a slick of the mouse click
    What would you like to use as search a field to enter anything and match if it's found in the of the columns?
    Like I asked this morning what you want to see of the record once selected?
    Wouldn't be a bad idea to answer questions, I hate to make assumptions and then come up with something that is not what was asked.

  5. #5
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Search and display a record on a userform

    Hi, you'll be awake or waking up now, I'm off to bed.
    I edited your blank FindForm and maybe this helps you, you will have to add the code to show the data with the selected record, but see if this the idea you were looking for

    I gave the table a name , i don't like default names like Table 1 and so
    I cleared the empty table rows your code will have to include add table row or delete table row or whatever.
    Try the form and see if it works for you,
    When the form opens you can type text in the textbox and it will search-as-you-type
    I'm off to bed.
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    09-15-2014
    Location
    QLD Australia
    MS-Off Ver
    2010
    Posts
    18

    Re: Search and display a record on a userform

    Quote Originally Posted by Keebellah View Post
    Hi, you'll be awake or waking up now, I'm off to bed.
    I edited your blank FindForm and maybe this helps you, you will have to add the code to show the data with the selected record, but see if this the idea you were looking for

    I gave the table a name , i don't like default names like Table 1 and so
    I cleared the empty table rows your code will have to include add table row or delete table row or whatever.
    Try the form and see if it works for you,
    When the form opens you can type text in the textbox and it will search-as-you-type
    I'm off to bed.
    Hi Keebellah, I'm up and about barely after you've gone to bed.
    To start off with, sorry for the infinite columns and rows, it was previously populated with data from the original register, which I deleted the data for but no the actual table rows and columns. but leaving the existing rows and columns (as you can tell, the old register was pretty clunky, and the columns headed off into infinity).

    The search function is fantastic! The notes in the code are very appreciated and easy to follow. This exactly what I was looking to achieve. Thankyou very much!!

  7. #7
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Search and display a record on a userform

    Glad to hear that.
    Happy coding

  8. #8
    Registered User
    Join Date
    09-15-2014
    Location
    QLD Australia
    MS-Off Ver
    2010
    Posts
    18

    Re: Search and display a record on a userform

    Now I just need to work out how to populate the view/edit userforms based off the selection

  9. #9
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Search and display a record on a userform

    Hi, it seems that there wre some problems with the hosting server and I could not post an answer.
    Glad you liked it and hope you can put it to good use.
    I have attached a slightly modified version of the userform.
    Added a reset (when you have typed or selected something) and place the actual record counter below the search box
    Next to the Cancel button a textbox that will contain the selected record number (row in the table which is not the row in the worksheet)
    You could use the forms you have but need to add the possibility to read a selected record and show the values, this to avoid adding extra forms with almost the same code.

    See if you can make something of this short explanation but I would like to help if you need it.
    Attached Files Attached Files

  10. #10
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Search and display a record on a userform

    Another option (and this is the last time I'll stalk you )
    I added a column to the table (at the end) and hid it, is contains all the records concatenated into one cell per row (except the dates) and the alignment is shrink to fit because you do not need to read it.
    In the (ActiveX) textbox you just start typing what you want and the filter will filter the data using that last column contains criterium on-the-fly
    If the database becomes bigger there will be a little lag, but it works, then you just need to add code to select a record using either doubleclick or right click
    Attached Files Attached Files

  11. #11
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Search and display a record on a userform

    Well, one more then
    Try this one, it permits to select view and edit a record. No distinction between view and edit, but y=it selects a record and you can edit it and submit the changes.
    Have not tested everything but give it a shot.
    Attached Files Attached Files

  12. #12
    Registered User
    Join Date
    09-15-2014
    Location
    QLD Australia
    MS-Off Ver
    2010
    Posts
    18

    Re: Search and display a record on a userform

    Phew, sorry for the late reply, I was away for the weekend and didn't have access to my files!

    Not be over the top, but your work is fantastic.

    I did work on a new user-form to use for viewing and editing, which is designed to provide all the information on one screen - so the user can get a quick overview without having to go through the tedious next/back sections like for the create new userform.
    I have attached a document with the userform I would like to use - I'm not 100% sure if I got it right - I want it to display information that cannot be changed, but can still be highlighted for copy/pasting by user (eg. they want to copy and paste across into a word doc. or for printing a label) and then the edit option would be for changing or adding to the record. I can't seem to wrap my head around how to link the search result with auto-filling the form though.

    (I seem to be getting an error when using the edit/view selected row button). I might not have merged the code/documents correctly.
    Edit. Updated the document upload - fixed up some stray code/double up caused by merge.
    Attached Files Attached Files
    Last edited by ania1224; 04-16-2018 at 09:51 PM. Reason: updated file.

  13. #13
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Search and display a record on a userform

    'Morning, I'm off to work now, will check it out this afternoon.

  14. #14
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Search and display a record on a userform

    I checked the file you attached, but you left out all the code I modified in the userforms to make it work , so no wonder it won't work with your form added.

    Well, that means or I correct all the code but don't know if you added modifications in this file outside copying some of my code and adding your userform.
    I think I'll copy your userform to the last version I uploaded and see if I can do something with it.

  15. #15
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Search and display a record on a userform

    Can you explain what you want to achieve with is ViewForm you added?
    It's full of Listboxes instead of Textbox fields? If it's to view then you view a record, but now I honestly do not understand what you want to do with this form
    you added the folloing 'explanation'in the vba code
    'when activated, we want the list boxes to be populated.
    'list boxes used to prevent editing, but also to allow copying an highlighting of content

    'type of trader
    A listbox is to show a list not a single value, a textbox can be used and set it locked so it cannot be edited.
    I honestly do no understand this form

    I made some modifications to the code so it works and no errors but no filling of the userform.
    I have attached the V3 file again but with your 'construction' for the viewing and since the Listbox give no indication of which field is which listbox you've got some 'homework'

    The worksheet UserformControls shows the list of all the controls for the 4 userforms, CorpForm, IAForm, SoleTraderForm and ViewForm with the 'anonymous' listboxes.
    Attached Files Attached Files

  16. #16
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Search and display a record on a userform

    Hi there, I hope my tone didn't scare you off. I took a look at what you tried and made modifications, The VBA-code of this file all fits together so if you want to use it in your own file you will have to take all the modules.
    I also noticed that you (probably by accident) change the last table's column formula (hidden one) and this caused that not all records would be identified if you started typing something, Annies pies was not selectable.
    I reorganized your ViewForm and address it using code I found.
    Try this file out with that dat that is there.
    There is A Reference worksheet (hidden) that is used to populate the viewform and could also be used when reading data for any of the other three forms, but that is not yet tested.

    The EDIT button and the Edit in the find window all invoke the ViewForm and the fields are locked. Listboxes are not the solution for what you were trying to do.
    I have three global booleans AddData, EditData and ViewData which are set for each situation using the UDf setWhat

    I learned some new tricks while rewriting your code and looking for a way to simplify things, so this was a fun challenge as well as a learning moment
    Attached Files Attached Files

  17. #17
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Search and display a record on a userform

    Minor corrections and added a Prev and Next button to the ViewForm
    Attached Files Attached Files

  18. #18
    Registered User
    Join Date
    03-04-2019
    Location
    Wales
    MS-Off Ver
    Office 365
    Posts
    2

    Re: Search and display a record on a userform

    This was just what I was looking for, I used the FindWindow form and altered to suit my worksheet and columns.

    Keebellah Thanks

  19. #19
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Search and display a record on a userform

    You're welcome

  20. #20
    Registered User
    Join Date
    03-04-2019
    Location
    Wales
    MS-Off Ver
    Office 365
    Posts
    2

    Re: Search and display a record on a userform

    Would it be possible to add some option buttons to choose which worksheet to search.
    I have worksheets "Members paid" and "Members Due".
    it would be great if I could do this.

  21. #21
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Search and display a record on a userform

    I suggest you start your own post with this question and attach the file too

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Look up a specific record in Data File and display in UserForm ListBox
    By HJHamm in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-28-2016, 03:56 PM
  2. [SOLVED] Userform to search worksheet and display data back to the userform
    By zip247 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-05-2015, 05:46 AM
  3. Userform to display last record on a sheet
    By adebayo in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 07-10-2013, 02:47 PM
  4. How to search record from sheet & display it to UserForm.
    By Mr82 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-26-2013, 05:09 PM
  5. userform Help (Search, Modify, Delete and Move a Record)
    By anuji.de.silva in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-03-2013, 09:20 AM
  6. Display last record in Userform
    By vba-lover in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-03-2007, 11:11 PM
  7. userform record search
    By by1612 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-25-2006, 08:01 AM

Tags for this Thread

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