+ Reply to Thread
Results 1 to 11 of 11

UserForm: Command Button enters numeric value to text box

Hybrid View

  1. #1
    Registered User
    Join Date
    12-03-2013
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    50

    UserForm: Command Button enters numeric value to text box

    Good Evening,

    UserForm1 has three text box: TxtBoxA, TxtBoxB and TxtBoxC. UserForm1 has three command buttons: CommandButton1, CommandButton2 and CommandButton3. Each button will be a assigned with a numeric value of 1,2 and 3 respectively.

    My desire is when I select any TxtBox - ie TxtBoxA - with my curser and then click any CommandButton, the value of that button will be entered into the TxtBox.

    The concept is similar to a number keypad. A backspace command button would be a feature, too.

    So far I have this code assigned to CommandButton1:
    TxtBoxA.Value = TxtBoxA.Value & "1"
    However, the focus is set to TxtBoxA, only.

    Thanks,
    Gal403

  2. #2
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: UserForm: Command Button enters numeric value to text box

    No value property for textbox, only text
    If solved remember to mark Thread as solved

  3. #3
    Registered User
    Join Date
    12-03-2013
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    50

    Re: UserForm: Command Button enters numeric value to text box

    Thanks for the reply. Do I understand your reply correctly, a Userform TextBox cannot receive a numeric value?

  4. #4
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: UserForm: Command Button enters numeric value to text box

    if you enter the number 3 the textbox returns the text "3"
    http://msdn.microsoft.com/en-us/libr...vs.110%29.aspx
    Last edited by patel45; 01-16-2014 at 04:28 AM.

  5. #5
    Registered User
    Join Date
    12-03-2013
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    50

    Re: UserForm: Command Button enters numeric value to text box

    Are you suggesting my inquiry should be worded differently?

  6. #6
    Valued Forum Contributor xlbiznes's Avatar
    Join Date
    02-22-2013
    Location
    Bahrain
    MS-Off Ver
    Excel 2007
    Posts
    1,223

    Re: UserForm: Command Button enters numeric value to text box

    I would suggest you to have another text box or a label with the visible property set to invisible.

    Set the text value to 1 , 2 and so on based on the text box clicked. Let us assume that the invisible text box is called as txt_Sel

    Private Sub TextBox1_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
    txt_sel.Text = 1
    End Sub
    
    Private Sub TextBox2_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
    txt_sel.Text = 2
    End Sub
    When the user clicks the command box assign the value to that text box like this :
    Private Sub CommandButton1_Click()
    UserForm1.Controls("TextBox" & txt_sel.Text).Text = 100
    End Sub
    Happy Computing ,

    Xlbiznes.

    To show your appreciation please click *

  7. #7
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,199

    Re: UserForm: Command Button enters numeric value to text box

    Hi, patel45,

    No value property for textbox, only text
    Can you show me where you found that because any Textbox on a UserForm has a Value. Awaiting your information.

    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  8. #8
    Registered User
    Join Date
    12-03-2013
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    50

    Re: UserForm: Command Button enters numeric value to text box

    Hell xlbizniss,

    Thank you for the reply and I apologizes it's taken me over a month to get to you. I created a sample userform and appliedSAMPLE 1.xlsm your VBA code but I appear to get an error that I can't locate. Can you assist?

    Gal403SAMPLE 1.xlsmSAMPLE 1.xlsm

  9. #9
    Registered User
    Join Date
    12-03-2013
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    50

    Re: UserForm: Command Button enters numeric value to text box

    Sorry for not proofing my last post. Too many redundant errors. Let me try again:

    Hello xlbizniss,

    Thank you for the reply and I apologizes it's taken me over a month to get to you. I created a sample userform and applied your VBA code but I appear to get an error that I can't locate. Can you assist?

    SAMPLE 1.xlsm

    Gal403

  10. #10
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,199

    Re: UserForm: Command Button enters numeric value to text box

    Hi, Gal403,

    maybe you should hve a look at class programming for this.

    Option Explicit
    
    Dim mstrTextbox As String
    
    Private Sub cmdDelete_Click()
    If Len(mstrTextbox) > 0 Then
      With UserForm1.Controls(mstrTextbox)
        If Len(.Text) > 0 Then
          .Text = Left(.Text, Len(.Text) - 1)
          mstrTextbox = vbNullString
        End If
      End With
    End If
    End Sub
    
    Private Sub CommandButton1_Click()
    If Len(mstrTextbox) > 0 Then
      UserForm1.Controls(mstrTextbox).Text = 1
    '  UserForm1.Controls(mstrTextbox).Text = UserForm1.Controls(mstrTextbox).Text & "1"
      mstrTextbox = vbNullString
    End If
    End Sub
    
    Private Sub CommandButton2_Click()
    If Len(mstrTextbox) > 0 Then
      UserForm1.Controls(mstrTextbox).Text = 2
      mstrTextbox = vbNullString
    End If
    End Sub
    
    Private Sub CommandButton3_Click()
    If Len(mstrTextbox) > 0 Then
      UserForm1.Controls(mstrTextbox).Text = 3
      mstrTextbox = vbNullString
    End If
    End Sub
    
    Private Sub CommandButton4_Click()
      UserForm1.Controls(mstrTextbox).Text = 4
      mstrTextbox = vbNullString
    End If
    End Sub
    
    Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    mstrTextbox = "Textbox1"
    End Sub
    
    Private Sub TextBox2_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    mstrTextbox = "Textbox2"
    End Sub
    
    Private Sub TextBox3_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    mstrTextbox = "Textbox3"
    End Sub
    
    Private Sub TextBox4_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    mstrTextbox = "Textbox4"
    End Sub
    Ciao,
    Holger

  11. #11
    Registered User
    Join Date
    12-03-2013
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    50

    Re: UserForm: Command Button enters numeric value to text box

    Thank you. I'll give it a try.

+ 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] Command Button on Userform appear sunken?
    By mc84excel in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-16-2013, 07:13 PM
  2. Hiding a Command Button in a UserForm
    By dvoit91 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-29-2011, 11:28 PM
  3. UserForm Command button
    By aCmE in forum Word Programming / VBA / Macros
    Replies: 7
    Last Post: 01-10-2011, 11:53 AM
  4. Userform Command Button to open new userform
    By JamesT1 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-08-2010, 12:02 PM
  5. VBA Userform Issue - Command Button / msg Box
    By teeks in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 01-07-2010, 11:37 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