![]() I have a textbox on a userform. If the user fails to enter anything in this textbox, I need to trap that to force an entry. I can do this easily enough, but after notifying the user tht they need to make an entry, I want the focus to return to the textbox. Open the document in Word 2016, then use File> Convert Document, or Using Word 2013 you might try doing the type of procedure Please mark HELPFUL or ANSWERED as appropriate to keep list as clean as possible ☺ Regards, Bob J. It will however print the text or (Outlook is configured to use Word as its text editor) once emails are sent the body of them can be viewed by the recipient or the sender. In the Find What box, type the placeholder text. In the Replace With text box, enter ^c to indicate the last item copied to the Clipboard. Click Find Next and then click Replace, or click Replace All. Make sure that the dimensions of the image can fit into the space you want for them. Otherwise, you will have to manually tweak the images in place. Right now, it doesn't do that. Here is my code: Private Sub txtAnswer_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer) Select Case KeyCode Case 13: If Me.txtAnswer.Value = ' Then temp = MsgBox('You need to enter an answer!' , vbCritical + vbOKOnly, 'No Answer Found!' ) Me.txtAnswer.SetFocus Else recordAnswer End If End Select End Sub This code works fine in that the message box pops up if the textbox is left blank. After clearing the message box, if I hit enter immediately again, the message box reappears, suggesting that the focus is on the textbox. However, if I try to enter a character (like the number '1' for example) nothing appears in the textbox. Can anybody suggest how I can get the focus back on this textbox in a way that will allow the user to enter data? Why are you not using an 'ok' button to complete the action? You should not bother users with messages while they are typing in a form. Do it at the end. Private Sub OK_Click() '// Validate form If txtAnswer.Text = vbNullString Then MsgBox 'You need to enter an answer!' , vbExclamation, 'No Answer Found!' TxtAnswer.SetFocus Exit Sub End If '// You have reached here so form is correct carry on recordAnswer End Sub If you really want to use the behaviour you asked for then try this: Private Sub txtAnswer_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer) Select Case KeyCode Case 13: If Me.txtAnswer.Value = ' Then temp = MsgBox('You need to enter an answer!' , vbCritical + vbOKOnly, 'No Answer Found!' Page Background Word) KeyCode = 0 Else recordAnswer End If End Select End Sub The problem is that in your code you are setting focus but the enter key is firing afterwards. You don't need to set focus because the textbox already has the focus you just need to cancel the enter key. This is a math program for kids. The idea is that the student is cycling through basic math problems. There is one textbox on the form where they enter the answer to the problem posed. 2 + 2 and they enter '4'). Upon entering their answer, they hit 'enter'. They are then told whether their answer is correct or not, but the form does not go away. A new problem is simply posed to them. They only hit the 'OK' button when they are finished answering questions and wish to see their results. – Jun 6 '12 at 1:14 •. Download - Fun Dog Pro Bubble Shooter - Some important keyboard shortcut keys of Microsoft Word, these key will work all the version of Word like, 2003, 2007, 2010, 2013 and 2016. Free mac font downloads. Remove Picture Background WordThe other answers seem really complicated. I had a similar problem and really wanted a text warning. It seemed easier for me to just make an invisible label on the form that would show up if the input was incorrect. I also made the background of the label red so that the user would notice something was wrong. Doing it this way kept the cursor visible and right where they left off. Public Function amount(ByRef cont As MSForms.TextBox) As Integer 'makes sure that a number is used 'could change to account for decimals if necessary Dim i As Long On Error Resume Next i = 0 If (cont.Value = ') Then Exit Function Do While i.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |