# Part Tracker Customization error - Object reference not set to an instance of an object

**URL:** <https://www.epiusers.help/t/part-tracker-customization-error-object-reference-not-set-to-an-instance-of-an-object/93893>\
**Category:** Epicor ERP 10\
**Tags:** customization, e10\
**Created:** [August 30, 2022, 2:07pm UTC](https://www.epiusers.help/t/part-tracker-customization-error-object-reference-not-set-to-an-instance-of-an-object/93893 "2022-08-30T14:07:09Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![bwhite](https://www.epiusers.help/letter_avatar_proxy/v4/letter/b/c0e974/32.png) [@bwhite](https://www.epiusers.help/u/bwhite)\
**Post date:** [August 30, 2022, 2:07pm UTC](https://www.epiusers.help/t/part-tracker-customization-error-object-reference-not-set-to-an-instance-of-an-object/93893/1 "2022-08-30T14:07:09Z")

</div>

I have narrowed down the line that is causing this error but I don’t know enough to fix it, hope someone can help  
This is the code, The line between the messagebox’s is the current problem, I am sure the next line will have the same issue

public class Script  
{  
// \*\* Wizard Insert Location - Do Not Remove ‘Begin/End Wizard Added Module Level Variables’ Comments! \*\*  
// Begin Wizard Added Module Level Variables \*\*

```
// End Wizard Added Module Level Variables **

// Add Custom Module Level Variables Here **
private EpiDataView edvPart;
//private EpiDataView edvPartWhse;

public void InitializeCustomCode()
{
	// **Wizard Insert Location - Do not delete 'Begin/End Wizard Added Variable Initialization' lines**
	// Begin Wizard Added Variable Initialization

	// End Wizard Added Variable Initialization

	// Begin Wizard Added Custom Method Calls

	this.btnPrintLabels.Click += new System.EventHandler(this.btnPrintLabels_Click);
	// End Wizard Added Custom Method Calls
	EpiDataView edvPart = ((EpiDataView)(oTrans.EpiDataViews["Part"]));
	//EpiDataView edvPartWhse = ((EpiDataView)(oTrans.EpiDataViews["PartWhse"]));
}

public void DestroyCustomCode()
{
	// **Wizard Insert Location - Do not delete 'Begin/End Wizard Added Object Disposal' lines**
	// Begin Wizard Added Object Disposal

	this.btnPrintLabels.Click -= new System.EventHandler(this.btnPrintLabels_Click);
	// End Wizard Added Object Disposal

	// Begin Custom Code Disposal

	// End Custom Code Disposal
	this.edvPart = null;
	//this.edvPartWhse = null;
}

private void btnPrintLabels_Click(object sender, System.EventArgs args)
{
	// **Place Event Handling Code Here**

```

**MessageBox.Show(“btnPrintLabels\_Click”);**  
string partNum = edvPart.dataView[edvPart.Row][“PartNum”].ToString();  
**MessageBox.Show(partNum);**  
string descr = edvPart.dataView[edvPart.Row][“PartDescription”].ToString();  
//string location = edvPartWhse.dataView[edvPartWhse.Row][“PrimBinNum”].ToString();  
string mtlAnalysisCode = edvPart.dataView[edvPart.Row][“MtlAnalysisCode”].ToString();

```
	string filelocation = string.Empty;
	string outputLine = string.Empty;
	EpiNumericEditor nbrLblQty = (EpiNumericEditor)csm.GetNativeControlReference("58bf5c04-f44b-4ae3-82b7-dba3489c85c6");
	decimal completedQty = System.Convert.ToDecimal(nbrLblQty.Value);
	if(completedQty > 0)
	{
		for (int a = 1; a <= completedQty; a++)
		{
			filelocation = @"\\server\folder\";
			int secs = System.Convert.ToInt32(DateTime.Now.TimeOfDay.TotalSeconds * 100);
			filelocation = filelocation + "P" + secs.ToString() + a.ToString() + ".LBL";
			outputLine = "^XA" + Environment.NewLine;
			if (completedQty > 1)
			{
				if (a < completedQty)
				{
					outputLine = outputLine + "^MMT" + Environment.NewLine;
				}
				else
				{
					outputLine = outputLine + "^MMC" + Environment.NewLine;
				}
			}
			else
			{
				outputLine = outputLine + "^MMC" + Environment.NewLine;
			}
			outputLine = outputLine + "^FO20,20^ADN,36,20^FD" + partNum + "^FS" + Environment.NewLine;
			outputLine = outputLine + "^FO290,15^B3N,N,50,N,N^FD" + partNum + "^FS" + Environment.NewLine;
			outputLine = outputLine + "^FO20,75^ADN,28,10^FD" + descr + "^FS" + Environment.NewLine;
			outputLine = outputLine + "^FO20,115^ADN,28,10^FD" + mtlAnalysisCode + "^FS" + Environment.NewLine;
			//outputLine = outputLine + "^FO20,165^ADN,36,20^FD" + location + "^FS" + Environment.NewLine;
			//outputLine = outputLine + "^FO230,155^B3N,N,50,N,N^FD" + location + "^FS" + Environment.NewLine;

			outputLine = outputLine + "^XZ" + Environment.NewLine;
			using (var TCFile = new System.IO.StreamWriter(filelocation, true))
			{
				TCFile.WriteLine(outputLine);
				TCFile.Close();
			}
		}
	}
}

```

}

---

<div class="post-metadata">

**Author:** ![stoyanlevakov](https://www.epiusers.help/letter_avatar_proxy/v4/letter/s/e19adc/32.png) [@stoyanlevakov](https://www.epiusers.help/u/stoyanlevakov)\
**Post date:** [August 30, 2022, 2:33pm UTC](https://www.epiusers.help/t/part-tracker-customization-error-object-reference-not-set-to-an-instance-of-an-object/93893/2 "2022-08-30T14:33:29Z")

</div>

Hello Barry,

I can see that you declare a new **EpiDataView edvPart = …** in the InitializeCustomCode() Method. You don’t have to do that, just initialize it there:

```auto
// End Wizard Added Custom Method Calls
edvPart = ((EpiDataView)(oTrans.EpiDataViews["Part"]));
``
```

---

<div class="post-metadata">

**Author:** ![dr\_dan](https://www.epiusers.help/user_avatar/www.epiusers.help/dr_dan/32/48005_2.png) [@dr\_dan](https://www.epiusers.help/u/dr_dan)\
**Post date:** [August 30, 2022, 2:35pm UTC](https://www.epiusers.help/t/part-tracker-customization-error-object-reference-not-set-to-an-instance-of-an-object/93893/3 "2022-08-30T14:35:27Z")

</div>

Do you get the error when you first open the form? before any records are loaded?

---

<div class="post-metadata">

**Author:** ![bwhite](https://www.epiusers.help/letter_avatar_proxy/v4/letter/b/c0e974/32.png) [@bwhite](https://www.epiusers.help/u/bwhite)\
**Post date:** [August 30, 2022, 2:40pm UTC](https://www.epiusers.help/t/part-tracker-customization-error-object-reference-not-set-to-an-instance-of-an-object/93893/4 "2022-08-30T14:40:46Z")

</div>

I only get the error when I click the Print Labels button.

---

<div class="post-metadata">

**Author:** ![dr\_dan](https://www.epiusers.help/user_avatar/www.epiusers.help/dr_dan/32/48005_2.png) [@dr\_dan](https://www.epiusers.help/u/dr_dan)\
**Post date:** [August 30, 2022, 2:48pm UTC](https://www.epiusers.help/t/part-tracker-customization-error-object-reference-not-set-to-an-instance-of-an-object/93893/5 "2022-08-30T14:48:28Z")

</div>

I’m defnintely not an expert when it comes to this… could it have something to do with the button click code is being written when the form is loaded and there is no part record yet selected?

---

<div class="post-metadata">

**Author:** ![bwhite](https://www.epiusers.help/letter_avatar_proxy/v4/letter/b/c0e974/32.png) [@bwhite](https://www.epiusers.help/u/bwhite)\
**Post date:** [August 30, 2022, 2:58pm UTC](https://www.epiusers.help/t/part-tracker-customization-error-object-reference-not-set-to-an-instance-of-an-object/93893/6 "2022-08-30T14:58:45Z")

</div>

Thank you stoyanlevakov, that was the problem
