Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Object reference not set to an instance of an object

Object reference not set to an instance of an object.

Dim addCustsForm As CustAddForm ' a form that is part of the project
Dim providerStr As System.String
Dim dataSourceString As System.String

providerStr = "Provider='Microsoft.JET.OLEDB.4.0';"
dataSourceString = New String("Data Source='C:\Documents and Settings\jfitzpatrick\My Documents\Tester.mdb'")

CustDDCon.Open()
conCustCon.Open(providerStr & dataSourceString)
rcsCust.CursorType = ADODB.CursorTypeEnum.adOpenDynamic
rcsCust.Open("Customers", conCustCon)

addCustsForm.setupRecords(providerStr, dataSourceString)

The error occurs when I pass the variables to this sub routine, which is in a different form. When I "comment" out the addCustForms line, the programme runs without any hitches.

The sub routine is declared as follows:
Public Sub setupRecords(ByVal providerString As System.String, ByVal sourceString As System.String)

& the form is declared as Public Class CustAddForm

:confused:
[1114 byte] By [Madman] at [2007-11-11 7:05:47]
# 1 Re: Object reference not set to an instance of an object
You must either pass an existing instance of CustAddForm to this routine, or create an instance within the routine:

Dim addCustsForm As New CustAddForm

' -- or --

Dim addCustsForm As CustAddForm
addCustsForm = New CustAddForm()
Phil Weber at 2007-11-11 21:49:37 >
# 2 Re: Object reference not set to an instance of an object
:D

That has worked thanks

I have removed the varible call addForm and now replaced it with a global varible which has the following delcation:

Dim addCustsForm As New CustAddForm

& as you said it was missing the "New"
Madman at 2007-11-11 21:50:43 >