Group,

I'm working to use a second for to do task that will be populate texts boxes in the first form. However I'm getting an error that says, "An error occurred creating the form. See Exception.InnerException for details. The error is: Object reference not set to an instance of an object.

In Form1, where the code starts, the code looks like this:

Public Sub cbxEditLocation_Click(sender As Object, e As System.EventArgs) Handles cbxEditLocation.Click
        cbxDeleteLocation.Checked = False
        cbxNewEntry.Checked = False
        cbxEditLocation.Checked = True
        sTask = 1
        Popup_LocationEdit.ShowDialog()
    End Sub

Form2 never opens, but it looks like this:

Private Sub Popup_LocationEdit_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        If sTask = 1 Then
            txbFormType.Text = "Enter the Location to Edit"
        End If
        If sTask = 2 Then
            txbFormType.Text = "Enter the Location to Delete"
        End If
    End Sub

I've tried using "Popup_LocationEdit.Show()" with the same error message. Can someone tell me what's going on here and how to fix it? I know I've done this before. But I don't recall having this kind of error.

Thanks for your help.

Don

Recommended Answers

All 4 Replies

try something like this:

Public Sub cbxEditLocation_Click(sender As Object, e As System.EventArgs) Handles cbxEditLocation.Click
    cbxDeleteLocation.Checked = False
    cbxNewEntry.Checked = False
    cbxEditLocation.Checked = True
    sTask = 1
    Dim NewPLEdit as New Popup_LocationEdit
    NewPLEdit.ShowDialog()
End Sub

tinstaafl, It worked like it was supposed to. Can you explain to me what made this work? Why didn't my original code work?

Thanks for the help. This is perfect!

Don

If i'm not mistaken, it's because the form is a class, so like any class it needs to be instantiated before it can be used outside of the class. For instance you can't assign a value Integer, it has to be instantiated then you can assign a value, Dim NewInt As Integer. It works the same way, with forms.

I'll remember this. Thanks for the suggestion.

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.