Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Clear textboxes on a form using another form?

Posted on 2006-05-30
Medium Priority
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
  • 2

Expert Comment

ID: 16789371
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

Accepted Solution

zubin_kharas earned 2000 total points
ID: 16789387
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  formA.show() keyword to actually show you the changes.

Regards, Zubin

LVL 28

Expert Comment

ID: 16789389
try if this work
            Dim FormA As New FormA

Author Comment

ID: 16789505
Well Spotted Zubin,

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



Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Kernel Data Recovery is a renowned Data Recovery solution provider which offers wide range of softwares for both enterprise and home users with its cost-effective solutions. Let's have a quick overview of the journey and data recovery tools range he…

581 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