View Full Version : Solved: Run Code only if user types in a name
Djblois
08-24-2006, 08:44 AM
THis is the code that I wrote. However, it is cancelling weather the user inputs in the box or not. It should only pop up the message box if the user left the box blank or if they hit cancel. What am I missing?
On Error Resume Next
myInput = InputBox("What do you want to name the Report?")
If myInput Is Nothing Then
MsgBox "You did not Create a Sales Report. Please rerun report or press Cancel."
CallBlinco
End
Else
End IF
Try this
If IsNull(myInput) Then
instead of
If myInput Is Nothing Then
lucas
08-24-2006, 08:54 AM
Could you use a form with a textbox and have the ok button be disabled until they add text?
Private Sub Textbox1_Change()
If Textbox1.Value <> "" Then
CommandButton1.Enabled = True
Else
CommandButton1.Enabled = False
End If
End Sub
Djblois
08-24-2006, 08:54 AM
OBP,
That is working Opposite. It is always running the full code.
Try this version then
If (myInput) = "" Then
:o:
Djblois
08-24-2006, 09:39 AM
LUcas that worked great but there are two things that would make that the best.
1) How do I clear the textbox of text after you press ok or cancel
2) I want it so when you press enter after you type in the box it would automatically choose ok
I tried this code that I wrote:
enter = TextBox1.EnterKeyBehavior = True
If enter = True Then
CommandOk_Click
Else
End If
Djblois
08-24-2006, 09:44 AM
OBP,
That works perfectly. Thank you
lucas
08-24-2006, 10:05 AM
to clear the textbox:
Private Sub CommandButton1_Click()
Range("A1").Value = TextBox1.Value
TextBox1.Value = ""
End Sub
It would probably help to add this initialize statement too:
Private Sub UserForm_Initialize()
CommandButton1.Enabled = False
End Sub
lucas
08-24-2006, 10:08 AM
Here is a code for using enter to add your data....adjust to suit your needs:
Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, _
ByVal Shift As Integer)
If KeyCode = 13 Then
KeyCode = 0
Sheet1.Range("A65536").End(xlUp).Offset(1, 0) = Me.TextBox1.Value
Me.TextBox1 = vbNullString
Me.TextBox1.SetFocus
End If
End Sub
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.