Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Textbox Setfocus and Error #5 -- PLEASE HELP

Status
Not open for further replies.

MnM

Programmer
Nov 1, 2000
47
US
I am about to pull my hair out! I have a form and everything is working great on it except one thing, the textbox.setfocus. I’ve searched for solutions and I’ve tried all sorts of things. I read it has to be enabled and it has to be visible so I made sure my textbox was visible and enabled. Below is my code.

Code:
Private Sub Clear()
On Error GoTo ErrorHandler
2    txtGO.Text = ""
3    txtYard.Text = ""
4    txtDesc.Text = ""
5    txtAmount.Text = ""
6    chkApprove.Value = 0
7    txtTotal.Text = ""
8    chkApprove.Value = 0

9    If txtGO.Visible = False Or txtGO.Enabled = False Then
10      txtGO.Visible = True
11      txtGO.Enabled = True
12      txtGO.SetFocus
13   Else
14        txtGO.SetFocus
15   End If

ErrorHandler:
        If Err.Number <> 0 Then
            MsgBox &quot;Error # &quot; & Err.Number & &quot;on line # &quot; & Erl
        End If
End Sub

It errors on line 12 with an Error #5 Invalid Procedure Call or Argument. What also bugs me is the error doesn’t happen all the time, just sometimes and it is only happening when it is compiled. Does anyone have any suggestions?
 
I am not clear on exactly what you are getting the errors but if they are occuring only when the txtGo is not visible or not enabled you might want to try this

9 If txtGO.Visible = False Or txtGO.Enabled = False Then
10 txtGO.Visible = True
11 txtGO.Enabled = True
DoEvents
12 txtGO.SetFocus
13 Else
14 txtGO.SetFocus
15 End If
Anything is possible, the problem is I only have one lifetime.
[cheers]
 
Thanks foada. I put the DOEvents into my code, but it might take a day to see if it actually works (since it doesn't throw up the error everytime) I'll post if it works or not.
I have read that DoEvents are not always good to use though.

Did anyone else have any ideas?

 
MnM,

My thought was that if the txtGo is not enabled or visible that it could not receive the focus, therefore generating the error. By placing the doevents statement in the code VB would enable or make the control visible allowing it to receive the focus. Just a thought. Anything is possible, the problem is I only have one lifetime.
[cheers]
 
No it's not being called from Form_Load. It's being called from a different procedure. That procedure has to do with the form in which the textbox in the Clear procedure is, thus the form is shown already. Hopefully, I'll beable to find out today if the DoEvents will work. It's the first time the program will have been used since adding it.
 
Just wanted to let everyone know it appears to working great now. Haven't had any problems with it. Thanks so much foada, I think you hit it on the nose!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top