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.T ext = 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?
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.T
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?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
try if this work
Dim FormA As New FormA
FormA.TXT_OrderNo.text=""
Dim FormA As New FormA
FormA.TXT_OrderNo.text=""
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
By creating this new instance and hiding the old one there is really no need for ClearForm() after all.
Thanks
Daly__paul
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