How to close a specific form in vb.net?

112 views Asked by At

I use this code to close the name Frm_AutoSaleReceipt when I click the button on the other page. But it error like the image.

For Each fua As Form In Application.OpenForms
   If fua.Name = "Frm_AutoSaleReceipt" Then
      fua.Close()
   End If
Next

enter image description here

1

There are 1 answers

0
G3nt_M3caj On

Without loop all open forms you can find that in this way:

Dim frm As Form = Application.OpenForms.Item("Frm_AutoSaleReceipt")
If frm IsNot Nothing Then frm.Close()