+ Reply to Thread
Results 1 to 11 of 11

Excel UserForm Textbox problem

  1. #1
    Forum Contributor
    Join Date
    12-06-2021
    Location
    Fort Lauderdale, Florida. United States
    MS-Off Ver
    365
    Posts
    143

    Excel UserForm Textbox problem

    Hello!

    I manage a workbook with a userform. I have the code in the Save command button (below) which works as intended and is fully functional EXCEPT FOR ONE THING:

    I need for the textbox called TXT_Date to reject any entry put into it unless it is an actual date

    Users will be users and make mistakes and often i see a date as 01//01/2021 or just as 01/01 or as 01/01/20221.

    My end goal is to prevent the userform from saving data unless this criteria is met. If it isn't met then I'd like to inform the user that this field must be corrected.

    My question is What to do? and where in the code below to place it?

    I feel like i'm so close, but yet so far!!





    Private Sub COMM_BUTTON_SAVEINFO_Click()

    'This section requires user to fill-in ALL text boxes OR the macro will not run and show the msgbox

    If TXT_date.Value = "" Or TXT_AccountName.Value = "" Or TXT_DescriptiveText.Value = "" Or Not Not TXT_CreditAmount.Value = "" Then

    MsgBox "You must complete all fields, some boxes are still empty! ", vbCritical
    Exit Sub

    Else

    End If

    '-----------------------------------------------------------------------------------------------------------

    Dim LBpostingdate As String 'this is the name of the label(s)
    LBpostingdate = TXT_date.Text 'this is the name of the label pointing at the text box next to it

    Dim LBaccountname As String
    LBaccountname = TXT_AccountName.Text

    Dim LBdescriptivetext As String
    LBdescriptivetext = TXT_DescriptiveText.Text

    Dim LBcreditamount As Currency
    LBcreditamount = TXT_CreditAmount.Text


    Dim wsh As Worksheet
    Set wsh = ThisWorkbook.Worksheets("backend")

    Set tbl = wsh.ListObjects("table3")
    Dim lRow As ListRow
    Set lRow = tbl.ListRows.Add

    With lRow

    .Range(34) = LBpostingdate 'the .range(34) refers to the column number of the table where the information will be placed
    .Range(41) = LBaccountname
    .Range(56) = LBdescriptivetext
    .Range(47) = LBcreditamount

    MsgBox "Zero Pay entry yas been recorded successfully"



    End With
    End Sub

  2. #2
    Forum Expert CheeseSandwich's Avatar
    Join Date
    12-22-2021
    Location
    Kent, England
    MS-Off Ver
    365 - 2402-17328.20068
    Posts
    1,360

    Re: Excel UserForm Textbox problem

    How about something like:

    Please Login or Register  to view this content.

  3. #3
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,913

    Re: Excel UserForm Textbox problem

    01/01/20221 is a date though.

    You can do some basic validation with IsDate but it is quite liberal in its interpretation (01/01 would be accepted for example.)

    You might be better off using Day, Month and Year dropdowns.
    Rory

  4. #4
    Forum Expert CheeseSandwich's Avatar
    Join Date
    12-22-2021
    Location
    Kent, England
    MS-Off Ver
    365 - 2402-17328.20068
    Posts
    1,360

    Re: Excel UserForm Textbox problem

    Quote Originally Posted by rorya View Post
    01/01/20221 is a date though.
    You are right about the 01/01 bit but my system does not think that 01/01/20221 is a date.

  5. #5
    Forum Contributor
    Join Date
    12-06-2021
    Location
    Fort Lauderdale, Florida. United States
    MS-Off Ver
    365
    Posts
    143

    Re: Excel UserForm Textbox problem

    Quote Originally Posted by CheeseSandwich View Post
    How about something like:

    Please Login or Register  to view this content.
    Hi Cheese!!

    I tried incorporating that into the IF statement of the code, but it was a no-go. I think it mainly has to do with the syntax of how to incorporate it that i am having trouble with. How about putting a textbox that will say "Hey dummy! fix the entry here!" LOL

  6. #6
    Forum Contributor
    Join Date
    12-06-2021
    Location
    Fort Lauderdale, Florida. United States
    MS-Off Ver
    365
    Posts
    143

    Re: Excel UserForm Textbox problem

    Quote Originally Posted by rorya View Post
    01/01/20221 is a date though.

    You can do some basic validation with IsDate but it is quite liberal in its interpretation (01/01 would be accepted for example.)

    You might be better off using Day, Month and Year dropdowns.
    Thanks Rorya!! However, then that would create a new question for me on how to concatenate the "01" and "01" and "2021" into 01/01/2021 that will place it in one cell at the destination sheet!

  7. #7
    Forum Expert CheeseSandwich's Avatar
    Join Date
    12-22-2021
    Location
    Kent, England
    MS-Off Ver
    365 - 2402-17328.20068
    Posts
    1,360

    Re: Excel UserForm Textbox problem

    Not that you will use it but you would implement it like below:

    Please Login or Register  to view this content.

  8. #8
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,913

    Re: Excel UserForm Textbox problem

    You'd use DateSerial(year, month, day) with the relevant control values for each argument.

  9. #9
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,913

    Re: Excel UserForm Textbox problem

    Quote Originally Posted by CheeseSandwich View Post
    You are right about the 01/01 bit but my system does not think that 01/01/20221 is a date.
    It may be outside the computer's current range but it's still a date.

  10. #10
    Forum Expert CheeseSandwich's Avatar
    Join Date
    12-22-2021
    Location
    Kent, England
    MS-Off Ver
    365 - 2402-17328.20068
    Posts
    1,360

    Re: Excel UserForm Textbox problem

    Quote Originally Posted by rorya View Post
    It may be outside the computer's current range but it's still a date.
    I understand that but IsDate currently throws it out and probably will for at least a century

  11. #11
    Forum Contributor
    Join Date
    12-06-2021
    Location
    Fort Lauderdale, Florida. United States
    MS-Off Ver
    365
    Posts
    143

    Re: Excel UserForm Textbox problem

    Quote Originally Posted by CheeseSandwich View Post
    Not that you will use it but you would implement it like below:

    Please Login or Register  to view this content.
    Cheese, I hate it when people thank users like yourself with "Thanks, Cheese.. you're a genius". But i'm afraid i'll have to say it..

    "Thanks Cheese, you're a genius"

    That worked perfectly! I just need to edit the "Dummy" part for real before my boss runs into it, although.. it would fit the bill! LOL

    Thanks again,
    Rob

+ 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. TextBox SetFocus Problem on UserForm
    By jarekmos in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 01-22-2020, 02:32 AM
  2. Userform textbox date input problem
    By GraingerT in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-23-2019, 09:15 AM
  3. [SOLVED] Excel 2010 - Userform - display date from textbox in a label or textbox in 'ddd' format
    By theshybutterfly in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-29-2015, 10:54 PM
  4. [SOLVED] Userform called from another userform textbox - unload problem
    By barryleajo in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 03-27-2013, 01:09 PM
  5. Replies: 3
    Last Post: 05-07-2012, 09:46 PM
  6. [SOLVED] Userform TextBox TextAlign Problem-Bug?
    By Jason Moser in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-10-2006, 01:29 PM
  7. TextBox problem in a UserForm
    By SailFL in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-22-2005, 06:05 PM

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