+ Reply to Thread
Results 1 to 3 of 3

Thread: USERFORM textbox updates

  1. #1
    Registered User
    Join Date
    10-15-2010
    Location
    Sacramento, CA
    MS-Off Ver
    Excel 2007
    Posts
    54

    Talking USERFORM textbox updates

    Im creating a userform, and I have textbox that people put some information and the others are updated.

    For example I have:
    Public Sub TextBox7_enter()
    If TextBox3.Value = "" Then
    TextBox7.Value = 0
    Else
    TextBox7.Value = (TextBox3.Value * (TextBox27.Value / 100)) + TextBox3.Value
    TextBox7.Value = Format(TextBox7.Value, "#,##0.00")
    End If
    end sub
    then i have commandbutton which someone would click and then the information would automatically populate into the textbox7, (in this situation).
    Public Sub CommandButton1_Click()
     TextBox7.Repaint
    End Sub
    However, the textbox's (all of them) dont update, they only update when I hit enter in each one, of course because I have it set up as public textbox7_enter()

    I want to know a function where i can install it in the commandbutton1 and it will update automatically the textboxes with new data. (not to erase the data) but to calculate the data.

    anyone can help me, thank you, :0)
    Last edited by gill389; 05-17-2011 at 12:44 PM.

  2. #2
    Valued Forum Contributor
    Join Date
    04-11-2011
    Location
    Cincinnati, Ohio
    MS-Off Ver
    Excel 2007
    Posts
    262

    Re: USERFORM textbox updates

    Public Sub TextBox7_enter()
    If TextBox3.Value = "" Then
    TextBox7.Value = 0
    Else
    TextBox7.Value = (TextBox3.Value * (TextBox27.Value / 100)) + TextBox3.Value
    TextBox7.Value = Format(TextBox7.Value, "#,##0.00")
    TextBox8.Value = (TextBox3.Value * (TextBox27.Value / 100)) + TextBox3.Value
    TextBox8.Value = Format(TextBox7.Value, "#,##0.00")
    TextBox9.Value = (TextBox3.Value * (TextBox27.Value / 100)) + TextBox3.Value
    TextBox9.Value = Format(TextBox7.Value, "#,##0.00")
    End If
    end sub
    When you define all the values for each text box just repaint them all at the same time

    Public Sub CommandButton1_Click()
     TextBox7.Repaint
     TextBox8.Repaint
     TextBox9.Repaint
    End Sub

  3. #3
    Forum Guru snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,151

    Re: USERFORM textbox updates

    Use the right event.

    Public Sub TextBox7_Change()
      application.enableevents=false
    
      With TextBox3
          TextBox7.Text = iif(.Text="0",0,format(.Text * TextBox27.Text / 100 + .Text, "#,##0.00"))
      End with
    
      Application.Enableevents=true
    end sub
    Last edited by snb; 05-17-2011 at 10:32 AM.



+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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.2.0