Results 1 to 7 of 7

Userform problem with Textboxes and IF Statement

Threaded View

  1. #1
    Registered User
    Join Date
    08-23-2017
    Location
    South Afrca
    MS-Off Ver
    2016
    Posts
    3

    Userform problem with Textboxes and IF Statement

    Good day Guys

    This is my first post as a member (and a guy that just discovered forms) so my humble apologies if I am doing it wrong.

    So here goes:

    Ive got a Userform (Tax_Year_Details) that asks the User to select TAX YEAR DATE from a combobox(works perfect) and then to type opening odometer from a textbox1 and closing odometer from textbox2 and then finally total Business Kilometer in textbox4. All of these three textboxes are defined as

    Private Sub TextBox1_Change() 
    Range("b8").Value = TextBox1
    End sub 
    
    Private Sub TextBox2_Change()
    Range("b9").Value = TextBox2
    End Sub
    
    Private Sub TextBox4_Change()
    Range("b14").Value = TextBox4
    End Sub
    Once proceeding to click on the OK button it need to do a few checks and if there are errors a msgbox should give a describtion.

    .... example Textbox2 can not be less in value than textbox1. E.G Opening reading is 5000km (textbox1) and Closing reading 4000km(textbox2) = msgbox " Closing is less than opening - Re-enter"
    and
    ....example textbox3 can not be more than the difference of textbox2-textbox1. E.G. Traveled 2000km this year but opening reading was on 1000km and closing reading was on 1400km, = msgbox " Kilometers traveled is greater than kilometers from Opening and Closing specified"

    Private Sub Tax_year_OK_button_Click()
    ' First test that closing isnt less than opening
    If Range("B9") < Range("B8") Then
    MsgBox "CLOSING KILOMETERS IS LESS THAN OPENING KILOMTERS - Change Closing Kilometers"
    
    TAX_Year_date.Show
     
    'Second test if traveled in year for business is greater than Cell B9 - and cell B8
    ElseIf Range("B14") < Range("B13") Then
    MsgBox "TOTAL KILOMETERS TRAVELED IS LESS THAN BUSINESS KILOMTERS - Change Closing Kilometers"
    
    TAX_Year_date.Show
    
    'values are correctly entered proceed to next step
    Range("b9").Value = TextBox2
    End If
    
    Unload Me
    
    End Sub

    Some times the values work sometimes it doesnt - Not sure why not. See attached pictures







    Working Forum.png

    Not Working Forum MSGBox.png

    Not Working Forum MSGBox 2.png
    Attached Files Attached Files
    Last edited by Mariolockem; 08-24-2017 at 03:36 PM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Populating userform textboxes basis of results from 2 userform comboboxes
    By rlh in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 04-11-2017, 10:26 AM
  2. [SOLVED] Problem running Excel loop with Userform textboxes and checkboxes
    By dentler in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-20-2017, 01:59 PM
  3. Help Populating Textboxes in Userform, With Multipage Userform.
    By mdmorgan24 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-07-2012, 05:29 PM
  4. Write If/And statement for userform textboxes that are only visible
    By clemsoncooz in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-15-2012, 11:10 AM
  5. Userform TextBoxes
    By tqm1 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-29-2007, 09:04 AM
  6. [SOLVED] UserForm TextBoxes
    By Rob in forum Excel General
    Replies: 2
    Last Post: 08-05-2005, 10:07 PM
  7. [SOLVED] Userform Textboxes and Looping
    By Robbyn in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-17-2005, 12:06 AM

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