[RESOLVED] Unloading form problem
Hello All,
I had a problem with closing my form when the user clicked the cancel button, but that was resolved with the help of peejavery.
Now, I have a similar problem. This time when the user finishes calculating he will hit the submit button to send the calculation to a text box in the main form and then the form should close and go back to the main form.
Well, it will send the info the the text box on the main form, but the form will not close, it just keeps looping. I know it has to do with the textbox keeping the focus. I tried to change the focus to the next text box, but the form will still not close.
Any help would be appreciated.
[683 byte] By [
darruda] at [2007-11-20 0:39:53]

# 1 Re: [RESOLVED] Unloading form problem
Hm. Somehow the GotFocus routine is called again.
I don't know why, cause when single stepping it doesn't seem to do it.
But there is an easy solution: take the code out of the txtBox_GotFocus(Index) and put it in the txtBox_Click(Index) event sub. Works perfect then. You can even leave the focus where it was.
WoF at 2007-11-9 19:56:52 >

# 2 Re: [RESOLVED] Unloading form problem
Hello WoF,
Thanks for responding so quickly.
Yes, I have tried your solution and it works great, but the form will not pop up when the user tabs into it.
I want the user to be able to tab or click the box and the form will come up.
I've tried sending the focus to the next box like I did for the cancel code, but for some reason it will not work with the submit button.
Any ideas?
# 3 Re: [RESOLVED] Unloading form problem
What is happening is the TextBox is not losing the focus when the frmPop is Shown. So When frmPop is closed, the txtBox is re-getting the focus. To avoid this try setting the focus before you show the frmPop like this.
Private Sub txtBox_GotFocus(Index As Integer)
If Index = 7 Then
Text1(0).SetFocus
Load frmPop
frmPop.Show
End If
For intCount = 0 To 9
txtBox(intCount).SelStart = 0
txtBox(intCount).SelLength = Len(txtBox(intCount).Text)
Next intCount
End Sub
# 6 Re: [RESOLVED] Unloading form problem
Ah I see, I missed where the field regets the focus and refires the GetFocus event from within itself.
To prevent this you can also use a static variable like that:
Private Sub Text1_GetFocus(Index)
Dim again as Boolean
If Not again Then
again = True
...
'your code
...
again = False
End If
End Sub
This will allow the code within the event to be executed only once.
Also it is then not necessary to set the Focus to another field.
WoF at 2007-11-9 20:01:57 >
