Link to home
Start Free TrialLog in
Avatar of daly__paul
daly__paul

asked on

Clear textboxes on a form using another form?

Hi,

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
 
            Me.Hide()
            Dim FormA As New FormA
            FormA.ClearForm()
       
    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?
Avatar of zubin_kharas
zubin_kharas
Flag of New Zealand image

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
ASKER CERTIFIED SOLUTION
Avatar of zubin_kharas
zubin_kharas
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of iboutchkine
iboutchkine

try if this work
            Dim FormA As New FormA
            FormA.TXT_OrderNo.text=""
Avatar of daly__paul

ASKER

Well Spotted Zubin,

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

Thanks

Daly__paul