Question

I am getting an error when I try to create a new customer in Quickbooks Desktop.

The error: Object reference not set to an instance of an object.

The error occurs when I try to create the address for the customer.

 Customer qbdCustomer = new Customer();
                qbdCustomer.Name = txtCompany.Text;
                qbdCustomer.GivenName = txtFName.Text;
                qbdCustomer.FamilyName = txtLName.Text;                    
                qbdCustomer.Address[0].Line1 = txtAddress.Text;
                qbdCustomer.Address[0].Line2 = txtAddress2.Text;
                qbdCustomer.Address[0].City = txtCity.Text;
                qbdCustomer.Address[0].CountrySubDivisionCode = drpState.SelectedItem.Value;
                qbdCustomer.Address[0].PostalCode = txtZip.Text;
                qbdCustomer.Phone[0].FreeFormNumber = txtPhone.Text;
                qbdCustomer.Email[0].Address = txtEmail.Text;
                Customer customerAdded = (new DataServices(context)).Add(qbdCustomer);

Like I said the error occurs when it gets to the first address line. The Name, GivenName, and FamilyName fields work so it has to be something to do with the array for the address. I have been stuck on this for a couple days, any help would be greatly appreciated.

Was it helpful?

Solution

Create a PhysicalAddress object and assign it back to the Customer Address property:

Intuit.Ipp.Data.Qbd.PhysicalAddress customerAddress = new Intuit.Ipp.Data.Qbd.PhysicalAddress();
customerAddress.Line1 = txtAddress.Text;
customerAddress.Line2 = txtAddress2.Text;
customerAddress.City = txtCity.Text;
customerAddress.CountrySubDivisionCode = drpState.SelectedItem.Value;
customerAddress.PostalCode = txtZip.Text;
qbdCustomer.Address = new Intuit.Ipp.Data.Qbd.PhysicalAddress[]{ customerAddress };

The same applies to the Phone and Email properties.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top