+ Reply to Thread
Results 1 to 17 of 17

Userform with Static Search Criteria

  1. #1
    Registered User
    Join Date
    09-30-2022
    Location
    Indiana, United States
    MS-Off Ver
    Office 365 Pro Plus
    Posts
    9

    Userform with Static Search Criteria

    I am creating my first Userform and there are tons of resources and articles to help do that. I've also seen many examples of how to use textboxes or dropdowns to search and return results. I am looking for some direction or examples on how to create static search criteria. Example - when a user clicks a command button the userform will automatically initialize and load all results where column 1 = "new" or column1 = "in review" and column 3 = blank or column 3 = "pending". the user can then click next/prev and update any of the returned records. If anyone knows of some examples to reference? would be greatly appreciated.

    Thanks as always

  2. #2
    Forum Expert torachan's Avatar
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    4,304

    Re: Userform with Static Search Criteria

    attached example is a relatively simple method of achieving your goal.
    selecting one of the options allows you to then filter from the listbox relevant data.
    the rest of the form allows the basics of database management (add new / update / delete )
    Attached Files Attached Files
    Torachan,

    Mission statement; Promote the use of Tables, Outlaw the use of 'merged cells' and 'RowSource'.

  3. #3
    Forum Contributor
    Join Date
    10-02-2012
    Location
    UK
    MS-Off Ver
    Office 365
    Posts
    252

    Re: Userform with Static Search Criteria

    Without an example workbook, it's difficult to visualize what you are trying to achieve. If you could attach one, then myself and others should be able to guide in the right direction.

  4. #4
    Registered User
    Join Date
    09-30-2022
    Location
    Indiana, United States
    MS-Off Ver
    Office 365 Pro Plus
    Posts
    9

    Re: Userform with Static Search Criteria

    I didn't post a sample workbook because I'm just getting started. So far just have the form created but I have attached that, No code yet. I like the example you attached. I plan to have some fields not editable and some that are updateable depending on which command button is used to launch the form.

    I would like to eliminate the database search section and just have set criteria for the search depending on which command button was clicked to launch the form and then use Next and Prev buttons to navigate records. This form will be utilized by different departments and when they click their button I just want them to be able to update the information they need to. The teams are not very tech savy and the search section in torachan's example would be confusing for them. They currently just filter the sheet to try and see the ones they need to update but often many are missed. Also will utilize the form during a virtual meeting. currently we just use the spreadsheet and you can't see all the data at once and there is lots of scrolling back and forth.
    Attached Files Attached Files

  5. #5
    Forum Expert torachan's Avatar
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    4,304

    Re: Userform with Static Search Criteria

    please state which/where are the buttons you are launching form as I can only see one (this will determine the dynamics of the search routine)
    also how do you propose to identify the editable fields - when this is known it should be relatively straight forward to give you a solution.

  6. #6
    Registered User
    Join Date
    09-30-2022
    Location
    Indiana, United States
    MS-Off Ver
    Office 365 Pro Plus
    Posts
    9

    Re: Userform with Static Search Criteria

    I have attached an updated file. I added a new tab which identifies each cmd button that will launch the form. Also the search criteria for each button and the corresponding form elements that would have editable property set to FALSE. Hopefully this gives a clearer picture of what I am trying to accomplish. The form launch buttons are on the 2023 PSI tab

    Really appreciate any guidance or resources
    Attached Files Attached Files

  7. #7
    Forum Expert torachan's Avatar
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    4,304

    Re: Userform with Static Search Criteria

    check back on Friday - should have something together for you - I have got a couple of busy days otherwise it would have been sooner.

  8. #8
    Registered User
    Join Date
    09-30-2022
    Location
    Indiana, United States
    MS-Off Ver
    Office 365 Pro Plus
    Posts
    9

    Re: Userform with Static Search Criteria

    Appreciate any help and continuing to do some independent learning. I used to do a lot of web programming with SQL and VBScript but its been ages now. In my current role I think picking up some reading on VBA will continue to be beneficial but will be a slower journey as not at all part of my core responsibilities.

  9. #9
    Registered User
    Join Date
    09-30-2022
    Location
    Indiana, United States
    MS-Off Ver
    Office 365 Pro Plus
    Posts
    9

    Re: Userform with Static Search Criteria

    I have been searching for code that would function like I wanted with Next and Prev buttons from a search but no luck. seems most want to use the listbox technique to load search results. However, looking at the code in torachan's sample file and other articles I've read I had some thoughts on the logic that might make it possible I wanted to run by others in this group first before I even attempt to try and code anything out.

    1. Use a global module and have each worksheet cmd button call a different routine that sets a variable "SearchOpt" =1 or 2, etc along with calling Userform.Show
    2. In the Initialize sub run a .find/find next on the columns needed depending on the value of "SearchOpt". Since I can only search for one criteria with .Find have to nest a Do Loop to search for the additional criteria
    3. Anytime all criteria match load that row number into an array "ResultsArray"
    4. Use Next and Prev buttons in the Userform to move through each row using the row numbers in the ResultsArray

    If that sounds like a logical and efficient way to go about the problem I can try and start putting some code together? This is my first VBA project so I could be way off base.

    Also I thought it was pretty slick in torachan's file to loop through the controls with numeric identifiers instead of logical names. In the past with VBScript I always named form controls but has me thinking it might be easier to go back and rename mine. I'm using a combination of textboxes and comboboxes. Should I name them all with "textbox" to only have one loop?

  10. #10
    Forum Expert torachan's Avatar
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    4,304

    Re: Userform with Static Search Criteria

    Sorry I did not meet my self imposed deadline, life regrettably got in the way, I will continue over the weekend and hopefully keep my promise.
    Your 'thinking' is basically sound - you will see in my submission (when it is finished) I overlay the comboboxes with a textbox held in focus by the controls ZOrder property.
    This enables me to loop the 'clear' procedure just on the textboxes rather than the comboxes which when cleared then start having conflicts in further coding.

  11. #11
    Registered User
    Join Date
    09-30-2022
    Location
    Indiana, United States
    MS-Off Ver
    Office 365 Pro Plus
    Posts
    9

    Re: Userform with Static Search Criteria

    torachan

    I've created what I feel is a functional userform that functions exactly how I intended with one issue.

    When I select a button and the criteria it triggers for the search returns no results (QAS Review in the attached file) I throw a msg box that says no cases to review and then try to close the userform
    Please Login or Register  to view this content.
    but I get an error "Object variable or With block variable not set". I've tried several things and read posts but can't figure that part out.

    I'm open to any suggestions on upgrades to any of the code or potential issues I may not be aware I'm causing. One thing I'm definitely aware of is that it is not efficient to loop through every row in a table like I'm doing. However, I will never have more than 300 rows and ,most importantly, I could not get the find/find next to work. When it was working decently I could never match up the row in the worksheet to the row in the find range for getting and updating values.

  12. #12
    Registered User
    Join Date
    09-30-2022
    Location
    Indiana, United States
    MS-Off Ver
    Office 365 Pro Plus
    Posts
    9

    Re: Userform with Static Search Criteria

    Fresh brain this morning. Found the error was from trying to unload the form during initialization. I moved the logic above to the Activate routine and it works great. I didn't like that the form still appeared so I went back and changed the unload to Hide in the above code. then on the activate method on perform the unload. This seems to work for me.

    Please Login or Register  to view this content.

  13. #13
    Forum Expert torachan's Avatar
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    4,304

    Re: Userform with Static Search Criteria

    Taking a second look at your app. - to help I need to understand the logic behind the process - I would have normally expect the 'account' or 'patient' to have been the primary key with the 'PSI' as a secondary key, as with your selection of events you are still going through a labour intensive process - (as an extreme it could take 300 key presses to get to the last record in any section if all the fields have coincidently have a required search parameter meeting your input).
    I note now you have an extra button 'Add New' - this surely should be the initial start position of building the app - do you envisage another form or adaption of the existing form.
    You are using 'structured tables' for your 'database' and 'default' conditions which is good - but you are using cell range referencing to obtain stored details, far better to use 'table' referencing especially now you propose 'Add New' facility.
    Explain the logic so that I am able to understand to be of any assistance.

  14. #14
    Registered User
    Join Date
    09-30-2022
    Location
    Indiana, United States
    MS-Off Ver
    Office 365 Pro Plus
    Posts
    9

    Re: Userform with Static Search Criteria

    This is the final version of the form.

    cell range referencing to obtain stored details, far better to use 'table' referencing
    - I'm not fully understanding what you are saying here when you say to use table referencing.

    The main purpose this form was built was to help facilitate a meeting. This spreadsheet was used during a virtual meeting where each new or in review case is reviewed collectively. In current state the spreadsheet is screenshared and there are lots of "can you scroll left?", "can you scroll up?" "Can you stretch the cell, I can't read it all". The form was envisioned to allow a cleaner and one click view of all details of each row to speed up the process. So when you say that a large number may match you are correct. But if they are showing up because they meet criteria each one needs to be reviewed by the review board during the meeting. Any that do not get discussed just roll over into the next meeting which is on a monthly basis. In reality there are only about 15-20 new cases a month and usually all can be reviewed during the 1.5hr meeting.

    The additional buttons for each department (Coding, CDI, Compliance, QAS) are meant to simplify the process for them. Before the rows would be color coded if they needed to review and often were missed. The button should simply their view only showing them cases they need to review. The goal is for each department to go in and vote (Status Control combo - Agree, Disagree, Pending) and add in their comments prior to the meeting. That way all data is available during group discussion.

    The data for the first 6 columns comes from another software suite and must be copy and pasted into the spreadsheet. The add button was added on the back end because the goal of the form is not data entry but data view and update. I only thought it might be more convenient for the spreadsheet owner to have an easy way to add new rows this week.

    Hope this helps without getting too nitty gritty in the workflow.

  15. #15
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    2,760

    Re: Userform with Static Search Criteria

    Quote Originally Posted by cullie140 View Post
    Appreciate any help and continuing to do some independent learning. I used to do a lot of web programming with SQL and VBScript but its been ages now. In my current role I think picking up some reading on VBA will continue to be beneficial but will be a slower journey as not at all part of my core responsibilities.
    Something you may be interested in.
    He often times provides a link to an example spreadsheet with the code in place and of course the forms already drawn.
    Click the * Add Reputation button in the lower left hand corner of this post to say thanks.

    Don't forget to mark this thread SOLVED by going to the "Thread Tools" drop down list above your first post and choosing solved.

  16. #16
    Forum Expert torachan's Avatar
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    4,304

    Re: Userform with Static Search Criteria

    The data for the first 6 columns comes from another software suite and must be copy and pasted into the spreadsheet.
    Thank you for the clarification, I understand better now the purpose of the app.
    When I referred to 'table referencing' rather than 'range' referencing this is best illustrated in the above link.

    When you construct the individual lists that contain your required rows for editing they become a fragmentation of the main table you therefore lose the row reference.
    The method I generally use in situations such as this is to put the new list into an array with an added column at the end into which I put the row marker - when reading back the edited row to the main table this marker is used - I find this method far quicker than using search routines to find the row location.
    Regrettably I am busy for most of the week, I will however eventually put my solution on this site it may be of use to someone attempting a similar app.

  17. #17
    Forum Expert torachan's Avatar
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    4,304

    Re: Userform with Static Search Criteria

    Give the attached a trial - I have not had time to trouble shoot it completely.
    Attached Files Attached Files

+ 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] VBA Userform to search data in a table filtering results based on all search criteria
    By matt7416 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-05-2020, 05:09 AM
  2. [SOLVED] Search with Criteria on Userform
    By kirana2014 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-09-2017, 12:36 PM
  3. [SOLVED] Userform search 3 criteria
    By adamheon in forum Excel Programming / VBA / Macros
    Replies: 22
    Last Post: 12-29-2016, 03:02 PM
  4. Create a search userform to search using multiple criteria
    By Aleemaher in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-31-2014, 09:17 AM
  5. Userform To search based on 2 criteria Help
    By MDJ666 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-28-2013, 09:29 AM
  6. Userform Multi Criteria search
    By winkypinky in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-10-2012, 04:41 PM
  7. Userform Search Criteria
    By timarcarze in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 04-14-2011, 11:35 PM

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