I'm getting an invalid use of null error when calling my addZeroOH function. I have checked to see if there is a null and a message box never pops up; however, I do have a msgbox statement right before the call to see what the parameters look like and the MANUID parameter is missing. Therefore, when the addZeroOH function is called I get a Invalid Use of Null error. Furthermore, I have the MANUID and HITI parameters as optional parameters to try to avoid this. Any help would be greatly appreciated.

VB Code:
  1. 'ADDZEROOH()*******************************************************************
  2. Private Sub addZeroOH(PICKSL As String, PROD As Long, desc As String, _
  3.                       Optional ByVal manuid As String = "N/A", _
  4.                       Optional ByVal HITI As String = "N/A")
  5.     Dim sql As String
  6.    
  7.     Set newConnection = New ADODB.connection
  8.     newConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
  9.         "Data Source= G:\Finance\Inventory Control\CycleCount\DB\CycleCount.mdb"
  10.     newConnection.Open
  11.     Set newRecordSet = New ADODB.recordSet
  12.    
  13.     sql = "Insert into [MAIN] (PICKSL,SLOT,RES,PROD,[DESC],PACK," & _
  14.         "[MANU ID],HITIX, [PALLET ID],[PALLET QTY],DFP) VALUES ('" & _
  15.         PICKSL & "','',''," & PROD & ",'" & desc & "','','" & manuid & "','" _
  16.         & HITI & "',''," & 0 & ",'')"
  17. Debug.Print "INSERT INTO MAIN"
  18. Debug.Print sql
  19.    
  20.     newConnection.Execute sql
  21.    
  22.     sql = "Insert into [ALTER] (USERNAME,DATEOFCHANGE," & _
  23.         "TYPEOFCHANGE,PICKSL,SLOT,RES,PROD,[DESC],PACK," & _
  24.         "[MANU ID],HITIX, [PALLET ID],[PALLET QTY],DFP) VALUES (" & _
  25.         "'p6b0438',#" & Now() & "#," & "'ZERO OH ADDED','" & _
  26.         PICKSL & "','',''," & PROD & ",'" & desc & "','','" & manuid & "','" _
  27.         & HITI & "',''," & 0 & ",'')"
  28. Debug.Print "INSERT INTO ALTER"
  29. Debug.Print sql
  30.    
  31.     newConnection.Execute sql
  32.    
  33.     'newRecordSet.Close
  34.     'newConnection.Close
  35.     Set newRecordSet = Nothing
  36.     Set newConnection = Nothing
  37. End Sub
  38. 'ENDOF*ADDZEROOH()*************************************************************
  39.  
  40. 'LOOPTHRUZEROOH()**************************************************************
  41. Private Sub loopThruZeroOH()
  42.     Set connection = New ADODB.connection
  43.     connection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
  44.         "Data Source= G:\Finance\Inventory Control\CycleCount\DB\Z028.mdb"
  45.     connection.Open
  46.     Set recordSet = New ADODB.recordSet
  47.     recordSet.Open "PICKSL", connection, adOpenKeyset, adLockPessimistic, _
  48.         adCmdTable
  49.        
  50.     If (Not recordSet.EOF) Then
  51.         recordSet.MoveFirst
  52.     End If
  53.     Do Until recordSet.EOF
  54.         recordSet.Fields("PICKSL") = Replace(recordSet.Fields("PICKSL"), "'", "")
  55.         recordSet.Fields("PROD") = Replace(recordSet.Fields("PROD"), "'", "")
  56.         recordSet.Fields("DESC") = Replace(recordSet.Fields("DESC"), "'", "")
  57.         'recordSet.Fields("MANUID") = Replace(recordSet.Fields("MANUID"), "'", "")
  58.         recordSet.Fields("HITI") = Replace(recordSet.Fields("HITI"), "'", "")
  59.         'recordSet.Fields("OH") = Replace(recordSet.Fields("OH"), "'", "")
  60.            
  61.         Set newConnection = New ADODB.connection
  62.         newConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
  63.             "Data Source= G:\Finance\Inventory Control\CycleCount\DB\CycleCount.mdb"
  64.         newConnection.Open
  65.         Set newRecordSet = New ADODB.recordSet
  66.         newRecordSet.Open "MAIN", newConnection, adOpenKeyset, adLockPessimistic, _
  67.             adCmdTable
  68.        
  69.         Dim foundInMain As Boolean
  70.         foundInMain = False
  71.        
  72.         newRecordSet.MoveFirst
  73.         Do Until newRecordSet.EOF
  74.             If (newRecordSet.Fields("PICKSL") = recordSet.Fields("PICKSL")) Then
  75.                 foundInMain = True
  76.                 newRecordSet.Fields("PALLET QTY") = 0
  77.             End If
  78.             newRecordSet.MoveNext
  79.         Loop
  80.        
  81.         If (foundInMain = True) Then
  82.             newRecordSet.Close
  83.            
  84.             Dim sql As String
  85.             sql = "Insert into [ALTER] (USERNAME,DATEOFCHANGE," & _
  86.                   "TYPEOFCHANGE,PICKSL,SLOT,RES,PROD,[DESC],PACK," & _
  87.                   "[MANU ID],HITIX, [PALLET ID],[PALLET QTY],DFP) VALUES (" & _
  88.                   "'p6b0438',#" & Now() & "#," & "'ZERO OH UPDATED','" & _
  89.                   recordSet.Fields("PICKSL") & "','',''," & recordSet.Fields("PROD") _
  90.                   & ",'" & recordSet.Fields("desc") & "','','" & recordSet.Fields("manuid") & "','" _
  91.                   & recordSet.Fields("HITI") & "',''," & 0 & ",'')"
  92.  Debug.Print "INSERT INTO ALTER ZERO"
  93.  Debug.Print sql
  94.             newConnection.Close
  95.             Set newRecordSet = Nothing
  96.             Set newConnection = Nothing
  97.         Else
  98.             newRecordSet.Close
  99.             newConnection.Close
  100.             Set newRecordSet = Nothing
  101.             Set newConnection = Nothing
  102.                        
  103. If (recordSet.Fields("PICKSL") = "") Then
  104.     MsgBox ("PICKSL is null")
  105. ElseIf (recordSet.Fields("PROD") = "") Then
  106.     MsgBox ("PROD is null")
  107. ElseIf (recordSet.Fields("DESC") = "") Then
  108.     MsgBox ("DESC is null")
  109. ElseIf (recordSet.Fields("MANUID") = "") Then
  110.     MsgBox ("MANUID is null")
  111. ElseIf (recordSet.Fields("HITI") = "") Then
  112.     MsgBox ("HITI is null")
  113. End If
  114. MsgBox (recordSet.Fields("PICKSL") & ", " _
  115.       & recordSet.Fields("PROD") & ", " _
  116.       & recordSet.Fields("DESC") & ", " _
  117.       & recordSet.Fields("MANUID") & ", " _
  118.       & recordSet.Fields("HITI"))
  119. /////Next line gives error message/////////////////////////
  120.             Call addZeroOH(recordSet.Fields("PICKSL"), _
  121.                            recordSet.Fields("PROD"), _
  122.                            recordSet.Fields("DESC"), _
  123.                            recordSet.Fields("MANUID"), _
  124.                            recordSet.Fields("HITI"))
  125.         End If
  126.        
  127.         recordSet.MoveNext
  128.         DoEvents
  129.     Loop
  130.  
  131. End Sub
  132. 'ENDOF*LOOPTHRUZEROOH()********************************************************