Hi everyone, my form looks like the attached image.
The checkmark is associated with the following code and is supposed to add two records to tbl_SampleActivity.
It keeps giving me an "invalid use of null" error. I suspect this might have something to do with the yes/no field (Sampled). I am not sure...
Code:
Private Sub Save_Click()
On Error GoTo Err_Save_Click
Dim strUID As String
strUID = txtUID.Value
Dim intYear As Integer
intYear = txtYear.Value
Dim strSampler As String
strSampler = cmbSampler.Value
Dim strPermission As String
strPermission = cmbPermission.Value
Dim booBenthos As Boolean
booBenthos = chkBenthos.Value
Dim benthos As Boolean
If booBenthos = True Then
benthos = -1
ElseIf booBenthos = False Then
benthos = 0
End If
Dim booChem As Boolean
booChem = chkChem.Value
Dim chem As Boolean
If booChem = True Then
chem = -1
ElseIf booChem = False Then
chem = 0
End If
Dim strBenReason As String
strBenReason = txtBenReason.Value
Dim strChemReason As String
strChemReason = txtChemReason.Value
Dim strComments As String
strComments = txtComments.Value
Dim strSQL As String
' Add the benthos row
strSQL = "INSERT INTO tbl_SampleActivity (UID, Year, Sampler, SampleType, Sampled, Reason, PermissionType, Comments) VALUES (" _
& strUID & "," & intYear & "," & strSampler & ", 'Benthos'" & benthos & "," & strChemReason & "," & strPermission & "," & strComments & ")"
db.Execute strSQL
' Add the chem row
strSQL = "INSERT INTO tbl_SampleActivity (UID, Year, Sampler, SampleType, Sampled, Reason, PermissionType, Comments) VALUES (" _
& strUID & "," & intYear & "," & strSampler & ", 'Chemistry'" & chem & "," & strChemReason & "," & strPermission & "," & strComments & ")"
db.Execute strSQL
'DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
Exit_Save_Click:
Exit Sub
Err_Save_Click:
MsgBox Err.Description
Resume Exit_Save_Click
End Sub
Thanks!