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?
daly__paulAsked:
Who is Participating?
 
zubin_kharasCommented:
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()
 
    formA.show()
       
    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  formA.show() keyword to actually show you the changes.

Regards, Zubin

0
 
zubin_kharasCommented:
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
0
 
iboutchkineCommented:
try if this work
            Dim FormA As New FormA
            FormA.TXT_OrderNo.text=""
0
 
daly__paulAuthor Commented:
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
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.