Hey, all, this is my first thread, and I am pretty new to VBA, so bear with me if it is a little rough around the edges.
I am having an issue with Access crashing during an attempt to add a new record to a Recordset. The code below is similar to one used in other systems I have coded, and when I use my name as strInspector, it works properly with no problems. However, if i use any of the other inspector names (selected from a drop-down box) it crashes the program. There is no error warning, and no alert. It simply crashes and reboots the program. Any suggestions?
Code:
Function StoreSerial(SN, SO, RN, PN, Optional strInspector As String)
If SNexists(SN) = True Then 'SNsxists returns true if SN is already in database
Exit Function
End If
Dim SSc As ADODB.Connection
Dim SSs As New ADODB.Recordset
Set SSc = CurrentProject.Connection
SSs.ActiveConnection = SSc
SSs.Open "SerialNumbers", , adOpenDynamic, adLockOptimistic
If strInspector <> "" And Not IsNull(strInspector) Then
SSs.AddNew Array("SerialNumber", "ShopOrder", "ReleaseNumber", "PartNumber", "PrimaryInspector"), Array(SN, SO, RN, PN, strInspector) 'crashes here, but only when strInspector is certain names
Else
SSs.AddNew Array("SerialNumber", "ShopOrder", "ReleaseNumber", "PartNumber"), Array(SN, SO, RN, PN) 'never crashes when this one is run instead.
End If
CloseSS:
Set SSc = Nothing
SSs.Close
SSs.ActiveConnection = Nothing
End Function