Curious Cursor Issue - TextBox UserForm

03856me

Active Member
Joined
Apr 4, 2008
Messages
297
I am running a BeforeUpdate event which validates the entry then if the value is an error it clear the textbox and sets the focus back to the textbox. So far so good - the textbox is the focus but the cursor has disappeared which forces the user to use their mouse to select the textbox for entry. This is not a new problem, there are many posts out there but I have not had any luck finding a solution.

Here's the curious part - it works perfectly when I run it from the Visual Basic editor while in the UserForm code. BUT when I run it from my launch macro the cursor disappears when the SetFocus line is launched.

This is my Launch Macro that is assigned to the button on a menu and resides in a Module:
Code:
Sub EnterEdit()
    Frm_Input.Show False
End Sub

This is my user form macro:
Code:
Private Sub txt_specie_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
If txt_specie.Value > 15 And txt_specie.Value < 99 Then
MsgBox "Invalid Specie"
txt_specie.Value = ""
Me.txt_specie.SetFocus
   With txt_plot
        .SelStart = 1
        .SelLength = Len(.Text)
    End With
Cancel = True
End If
End Sub

Your help, as usual, is GREATLY appreciated!
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
You don't need to set focus actually. Cancel retains the focus on the control. I'm not sure I completely understand what you want to do here since you also manipulate another textbox, but the cursor is probably affected here by something else, not your textbox event (I don't lose the cursor when I use your code).
 
Upvote 0
Thanks for your quick reply. It was my mistake to have the txt_plot included, it should have been txt_specie. I changed it and removed the setfocus and it does stay in the txt_specie textbox, but no cursor is there and I have to use the mouse to click in the box to be able to enter anything.

How do I have the blinking cursor show up? Or more important, how can I make it accept input without using the mouse to choose somewhere inside the textbox?
 
Upvote 0
Also, you said it worked for you - are there any of the properties for the textbox that might be affecting this?
 
Upvote 0
In my testing it worked for me too - I had a play with a few different Textbox settings, and I couldn't recreate the behaviour you are seeing. If the workbook doesn't contain confidential information/can have any such info removed, you are welcome to send it to me and I will take a look?

I have sent you a PM with my email address - just ignore it if you don't want to send it out :)
 
Upvote 0
Thanks Firefly - emailed you file.

THE ISSUE IS THIS: the code runs perfectly from the VB editor, but when I run from a menu button using the Frm_Input.Show False command it doesn't show the cursor anymore.
 
Upvote 0
It's the MsgBox that is causing this. I haven't found of a way (yet) to effectively reset the focus to the relevant textbox but simply disabling the MsgBox line (ie commenting it out) means it works as you require (obviously with no warning though).
 
Upvote 0
Thank You Firefly - I will simply leave the beep and that will work, the main thing is it works. If you figure out a way let me know.
 
Upvote 0
This was a bit of a struggle. I encountered the same problem of the disappearing cursor when adressing the macro via a button.
The curious cursor appears only in combination of the msgbox and the form in modeless mode.


Replace Frm_Input.Show False
with
Replace Frm_Input.Show

This makes your form modal and your cursor should be blinking in the txt_specie field.


Please let me know if this helps.
 
Upvote 0
I appreciate your feedback 5 years after the project. I actually replaced the AfterUpdate event with the Exit event for that textbox. This works fine with the addition of IF statements and the Beep. My customer was pleased with the result. Here is the code in case others are looking for the resolution.

Code:
Private Sub txt_specie_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    If txt_specie.Value > 15 And txt_specie.Value < 99 Then
        Me.txt_specie.Value = ""
        Beep
        Cancel = True
    End If
   
    If txt_specie.Value = "" Then
        Beep
        Cancel = True
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,146
Messages
6,129,142
Members
449,488
Latest member
qh017

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top