Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

enable CommandButton if length text is select a value like 10 characters

I have been searching, but didn’t find anything about that ,I am trying to figure out if there is a way to autosave the input data from a textbox to the spreadsheet without the need of click a save button or keyboard .

hint: its just an autosave program I don’t want a lot of operations by the data entry

I want some command line like :
if length in textbox1 = 10 then start or activate CommandButton1 else dont do anything ?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Provided that after carrying out operations in CommandButton1 pointer which in this case is keyboard back to textbox waiting for another entry

Private Sub CommandButton1_Click()
Dim lastrow As Long
lastrow = WorksheetFunction.CountA(Sheets("data").Range("A:A"))

Sheets("data").Cells(lastrow + 1, 1).Value = lastrow
Sheets("data").Cells(lastrow + 1, 2).Value = UserForm1.TextBox2.Value
Sheets("data").Cells(lastrow + 1, 4).Value = UserForm1.TextBox1.Value
Sheets("data").Cells(lastrow + 1, 5).Value = Now()

Private Sub CommandButton2_Click()

UserForm1.TextBox2.Value = ""UserForm1.ComboBox1.Value = ""

>Solution :

Add this to your form:

Private Sub TextBox1_Change()
    If Len(TextBox1.Value) = 10 Then
        CommandButton1_Click
    End If
End Sub

This code will execute each time something causes the value of textbox1 to change, such as typing into it. As soon as the value in textbox1 has 10 characters, the code behind commandButton1’s click event will be executed.

Warning, if someone pasted 11 characters into textbox1, and then keeps typing, commandbutton1 code won’t execute

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading