+ Reply to Thread
Results 1 to 7 of 7

Error Message When Textbox in Userform Left Blank

  1. #1
    Registered User
    Join Date
    08-28-2012
    Location
    Canada
    MS-Off Ver
    Excel 2007
    Posts
    6

    Error Message When Textbox in Userform Left Blank

    Hi everyone,

    I am new to VBA and really appreciate all the tips, tricks and fixes that have been posted on this site. However, I have developed a problem to which I can't find a solution and was hoping that someone might be able to help me out.

    I am working on a database of surgical records. Each row represents one surgery. There are 25 columns which contain basic demographic information including date of birth, gender and date or surgery. I have designed a userform that searches this database with a number of steps all which occur simultaneously when the "search" button is pressed.

    1. user selects the Gender from option buttons (VBA: autofilters the database accordingly)

    2. User puts in the range of Operating Room dates and Date of Birth which they would like to see - eg: OR dates from 01-02-2005 to:04-06-2012 and DOB from 1-1-1950 to 1-1-2000 (VBA: autofilters the database)

    3. User has option of inputting 4 keywords, 2 are comboboxes which contain a list of surgeries, and 2 are normal textboxes (VBA: Uses .Find to locate any entries within the newly filtered range that match the keywords listed)

    4. any rows that fit the criteria get copied and pasted into a new sheet called "search results"

    The userform functions perfectly as long as the DATE boxes (outlined in step 2 above) contain values. As soon as these boxes are blank I try and search I get a Run-time error 13: type mismatch. I would like to be able to use the userform without having to always input dates (as the user will not always need to specify the OR dates and DOB). I was wondering whether there was a way that the userform can "disregard" the date boxes if they have been left empty?

    Thanks for any help you can provide. Let me know if you require clarification. I would prefer not to post a dummy copy of the workbook but can if it is needed.

    Thanks alot!

  2. #2
    Valued Forum Contributor
    Join Date
    03-23-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    1,093

    Re: Error Message When Textbox in Userform Left Blank

    Hello there,

    Can you please post your code so that we can fit it into your code accordingly?

    Thanks!

  3. #3
    Registered User
    Join Date
    08-28-2012
    Location
    Canada
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: Error Message When Textbox in Userform Left Blank

    Please Login or Register  to view this content.
    Last edited by Cutter; 09-04-2012 at 06:20 PM. Reason: Added code tags

  4. #4
    Forum Contributor thameem127's Avatar
    Join Date
    04-06-2012
    Location
    Jeddah,Saudi Arabia
    MS-Off Ver
    Excel 2003,Excel 2007
    Posts
    321

    Re: Error Message When Textbox in Userform Left Blank

    Attach file instead of writing detail explanation.

  5. #5
    Registered User
    Join Date
    08-28-2012
    Location
    Canada
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: Error Message When Textbox in Userform Left Blank

    Hey,

    Thanks for your quick replies. The workbook is attached I am having trouble with the FRMsearch userform.
    Attached Files Attached Files

  6. #6
    Forum Expert Cutter's Avatar
    Join Date
    05-24-2004
    Location
    Ontario,Canada
    MS-Off Ver
    Excel 2010
    Posts
    6,451

    Re: Error Message When Textbox in Userform Left Blank

    @ zaclim78

    Welcome to the forum.

    Please notice that code tags have been added to your post(s). The forum rules require them so please keep that in mind and add them yourself whenever showing code in any of your future posts. To see instructions for applying them, click on the Forum Rules button at top of the page and read Rule #3.
    Thanks.

  7. #7
    Registered User
    Join Date
    08-28-2012
    Location
    Canada
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: Error Message When Textbox in Userform Left Blank

    I have thought of a workaround. I will try and write some code which will automatically fill the date fields if they are left empty. I will fill the start dates with a constant that is well before any entered dates, and have the end date automatically fill with today's date.

    I haven't tried this via VBA yet but it works fine when I type it in manually. Let me know if you have any improvements to this workaround or any outright solutions!

    Thanks

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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