'How to close a specific form in vb.net?

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



Solution 1:[1]

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()

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 G3nt_M3caj