PDA

Click to See Complete Forum and Search --> : Closing the form with Command1_Click()


Coco_Nutty
Jan 28th, 2000, 01:49 AM
Dim Dan

Sub Form_Load()
Dan = 0
End Sub

Sub Command1_Click()
End
End Sub

Sub Text1_KeyPress(KeyAscii As Integer)

If KeyAscii = vbKeyReturn Then


SendKeys "{tab}"
KeyAscii = 0
Dan = Dan + 1
End If

End Sub
Sub Text2_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyReturn Then


SendKeys "{tab}"
KeyAscii = 0
End If
End Sub

Sub Text1_Gotfocus()
If Dan = 0 Then
Text1.Text = ""
Text2.Visible = False
Label2.Visible = False
Label1.Caption = "Place entry here"
Else
Text1.Visible = True
Label1.Visible = True
Text2.Visible = False
Label2.Visible = False
Text2.Text = ""
Label1.Caption = "Now place entry here"
End If
End Sub


Sub Text1_Lostfocus()
Text1.Visible = False
Label1.Visible = False
Text2.Visible = True
Label2.Visible = True
Text2.Text = ""
Text2.SetFocus
Label2.Caption = "Now place entry here"

End Sub

Sub Text2_LostFocus()
Text1.Visible = True
Label1.Visible = True
Text2.Visible = False
Label2.Visible = False
Text1.Text = ""
Text1.SetFocus
Label1.Caption = "Now place entry here"
End Sub


The problem I have above is that my Click()
does not shut down my program. It switches Text boxes instead. Is there an alternate way to shut down the form with Command1_Click()

Thanks
Coco

MartinLiss
Jan 28th, 2000, 02:08 AM
The problem with your code is that when you click Command1, the LostFocus events for your TextBoxes happen before the code in Command1. Think about how to redsign you project or put this as the first line in your LostFocus events:If Screen.ActiveControl.Name = "Command1" Then
Exit Sub
End If


Also, you should always explicitly assign a type to your variables, so Dan should be defined Dim Dan As Integer. Otherwise VB will treat it as a Variant. Variants are slow and they take up more space than most other types. You should also always give meaningful names to your objects, like txtFirstEntry instead of leaving it as Text1.

------------------
Marty
COGITO EGGO SUM
I think; therefore I am a waffle.

[This message has been edited by MartinLiss (edited 01-28-2000).]

Coco_Nutty
Jan 28th, 2000, 02:47 AM
Thanks

Marty


I think therefore my ass is too big