Clear textboxes on a form using another form?

Posted on 2006-05-30
Last Modified: 2010-04-23

I have looked at some similar postings on this topic but cant seem to get this working.

I have a FormA and FormB

The Textboxes and labels I wish to clear are on FormA.

On FormA I have this Public Sub.

 Public Sub ClearForm()
        ' Testing
        MsgBox("FormB has closed")

        TXT_OrderNo.Text = String.Empty
        LBL_CustName.Text = String.Empty
        LBL_PartName.Text = String.Empty
        LBL_QtyPartsManufactured.Text = String.Empty
        LBL_QtyPartsOrdered.Text = String.Empty
        LBL_DeliveryDate.Text = String.Empty
        LBL_TotalCycleHrs.Text = String.Empty
        LBL_CurrentTime.Text = String.Empty
        LBL_CustID.Text = String.Empty
        LBL_PartID.Text = String.Empty
        LBL_CountMach.Text = String.Empty
        LBL_PurchaseOrderID.Text = String.Empty

    End Sub

And on a click event of a button on FormB calls FormA ClearForm()

Private Sub BTN_Login_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTN_Login.Click
            Dim FormA As New FormA
    End Sub

It will display the test msgbox that I have at the Start of ClearForm() but textboxes and labels are still populated. I have also used TXT_OrderNo.text = "".

Any suggestions?
Question by:daly__paul
    LVL 2

    Expert Comment

    Hi there, not sure of the actua purpose, but a simpler way maybe to just create a new instance of the form.
    Also, instead of using string.clear, simply use control.text = ""  It does the same actual effect. ""  is not a blank space, its also not a system.dbnull.value so that way, youre safe guarded both ways.
    Cheers! Zubin
    LVL 2

    Accepted Solution

    Also in the above code:
    Private Sub BTN_Login_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTN_Login.Click
    >            Me.Hide()
     >           Dim FormA As New FormA
       >         FormA.ClearForm()
        End Sub

    I noticed that ur creating a new instance of the formA but ur not showing it. Nothe that a new instance will need to use keyword to actually show you the changes.

    Regards, Zubin

    LVL 28

    Expert Comment

    try if this work
                Dim FormA As New FormA

    Author Comment

    Well Spotted Zubin,

    By creating this new instance and hiding the old one there is really no need for ClearForm() after all.



    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Join & Write a Comment

    This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
    Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now