Results 1 to 3 of 3

Thread: Closing the form with Command1_Click()

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2000
    Location
    BC
    Posts
    11

    Post

    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

  2. #2
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Post

    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:
    Code:
    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).]

  3. #3

    Thread Starter
    New Member
    Join Date
    Jan 2000
    Location
    BC
    Posts
    11

    Post

    Thanks

    Marty


    I think therefore my ass is too big

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width