Well I figured it out, I just needed to close the dbconnection on form1 after the dbinsert.executenonquery. My hunch is that the db never lost focus, so the program couldn't grab the jobnumber value because it was still open and being written to. When the messagebox was placed there it took focus from the db. so here is the updated code.
Option Explicit On
Option Strict On
Imports System.Data.OleDb
Public Class assemblyForm
Inherits System.Windows.Forms.Form
Dim dbInsert As New OleDb.OleDbCommand
Dim dbConnect As New OleDb.enter code here`
Dim Line As String = Environment.NewLine
Dim ds As New DataSet, ds2 As New DataSet, ds3 As New DataSet
Dim da As OleDb.OleDbDataAdapter, da2 As OleDb.OleDbDataAdapter, da3 As OleDb.OleDbDataAdapter
Dim run As Integer, pcr As Integer, JobId2 As Integer, jobNum As Integer
Private Sub Form3_Load(sender As Object, e As System.EventArgs) Handles Me.Load
Try
'Open DB connection
dbConnect.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\crabara\Desktop\Project Alpha 3\MDB.accdb;Persist Security Info=False;"
dbConnect.Open()
'Autopopulate PartNo. textbox
da = New OleDb.OleDbDataAdapter("SELECT PartNumber FROM PCR_INFO", dbConnect)
da.Fill(ds, "list")
Dim col As New AutoCompleteStringCollection
Dim i As Integer
For i = 0 To ds.Tables(0).Rows.Count - 1
col.Add(ds.Tables(0).Rows(i)("PartNumber").ToString())
Next
txtPart.AutoCompleteSource = AutoCompleteSource.CustomSource
txtPart.AutoCompleteCustomSource = col
txtPart.AutoCompleteMode = AutoCompleteMode.Suggest
Catch ex As Exception
MessageBox.Show(ex.Message + Line + "Main Database Not Found" + Line + "Check form_AccessMaintenance source code" + Line + "Database Path", "Critical Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Me.Close()
End Try
End Sub
Private Sub btnSubmit_Click(sender As System.Object, e As System.EventArgs) Handles btnSubmit.Click
'Increment the Run
dbInsert.CommandText = "UPDATE PART_LIST SET Run = Run + 1 WHERE PartNumber='" & txtPart.Text & "'"
dbInsert.CommandType = CommandType.Text
dbInsert.Connection = dbConnect
dbInsert.ExecuteNonQuery()
'Gather Run from PART_LIST DB, put into variable
da = New OleDb.OleDbDataAdapter("SELECT Run FROM PART_LIST WHERE PartNumber ='" & txtPart.Text & "'", dbConnect)
da.Fill(ds, "Run")
run = CInt(ds.Tables("Run").Rows(0).Item(0))
'Gather PCR from PCR_INFO DB, put into variable
da2 = New OleDb.OleDbDataAdapter("SELECT PCRNumber FROM PCR_INFO WHERE PartNumber ='" & txtPart.Text & "'", dbConnect)
da2.Fill(ds2, "PCRNumber")
pcr = CInt(ds2.Tables("PCRNumber").Rows(0).Item(0))
'Set parameters for fields
dbInsert.Parameters.Add(dbInsert.CreateParameter).ParameterName = "PartNumber"
dbInsert.Parameters.Item("PartNumber").Value = txtPart.Text
dbInsert.Parameters.Add(dbInsert.CreateParameter).ParameterName = "PCRNumber"
dbInsert.Parameters.Item("PCRNumber").Value = pcr
dbInsert.Parameters.Add(dbInsert.CreateParameter).ParameterName = "Run"
dbInsert.Parameters.Item("Run").Value = run
dbInsert.Parameters.Add(dbInsert.CreateParameter).ParameterName = "JobNo"
dbInsert.Parameters.Item("JobNo").Value = txtJobNo.Text
'Add Values into Assembly DB
dbInsert.CommandText = "INSERT INTO Assembly(PartNumber,PCRNumber,Run,JobNo) VALUES(txtPart.Text,pcr,run,txtJobNo.Text);"
dbInsert.CommandType = CommandType.Text
dbInsert.Connection = dbConnect
dbInsert.ExecuteNonQuery()
MessageBox.Show("Job has been successfully submitted" + Line + txtPart.Text)
'Gather JobID from new job
da3 = New OleDb.OleDbDataAdapter("SELECT JobID FROM Assembly WHERE PartNumber ='" & txtPart.Text & "' AND JobNo ='" & txtJobNo.Text & "'", dbConnect)
da3.Fill(ds3, "JobID")
JobId2 = CInt(ds3.Tables("JobID").Rows(0).Item(0))
dbInsert.Parameters.Add(dbInsert.CreateParameter).ParameterName = "JobID"
dbInsert.Parameters.Item("JobID").Value = JobId2
'Add Values into Vinyl DB
dbInsert.CommandText = "INSERT INTO Molding(PartNumber,PCRNumber,Run,JobNo,JobID) VALUES(txtPart.Text,pcr,run,txtJobNo.Text,JobId2);"
dbInsert.CommandType = CommandType.Text
dbInsert.Connection = dbConnect
dbInsert.ExecuteNonQuery()
dbconnect.Close()
'Loads the newly created jobid into the vinyl form
Dim anotherForm As Vinyl
anotherForm = New Vinyl(JobId2)
anotherForm.Show()
End Sub