So I have a main form and 5 other forms. When I press a button on the main form, I want it to open Form2 and disable a certain button in form2 so that it cannot be used. I produced this code but the button is still active and there is no effect. Please help.

 Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        My.Forms.Form2.SaveVISACaseButton.Enabled = False
        My.Forms.Form2.SaveVISACaseButton.Visible = False
        Dim form2 As New Form2
        My.Forms.Form2.SaveVISACaseButton.Enabled = False
        My.Forms.Form2.SaveVISACaseButton.Visible = False
        form2.Show()
        Me.Hide()

    End Sub

It appears to me that if Form2 is already designed that you won't need to Dim a new one just show the one you have.

Declare object instance of form2 and use it to disable or visble a button in form2.
You already declare it but you didn't use it.
Try this :

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    Dim form2 As New Form2
    form2.SaveVISACaseButton.Enabled = False
    form2.SaveVISACaseButton.Visible = False
    form2.Show()
    Me.Hide()
End Sub
commented: Nice. +2
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.