In my access database, I have a table for the master list of items discussed in a training meeting. If a certain item was discussed in a meeting, then the value in the database is 1, if it was not discussed, then the item is 0.
I'm trying to get these values into checkboxes on my form, checked if the value is 1 and unchecked if 0.
However when I run it, I get a "NullReferenceException was unhandled. Object reference not set to an instance of an object"
The code for that subroutine is:
Private Sub NavigateTrainingItems()
chkDrugAlcoholPolicy.Checked = False
chkElectricalSafety.Checked = False
chkEmergencyResponse.Checked = False
chkFirstAid.Checked = False
chkForkliftTraining.Checked = False
chkGlobalGap.Checked = False
chkHeatStress.Checked = False
chkLadderSafety.Checked = False
chkLiftingItems.Checked = False
chkOperatingEquipInspection.Checked = False
chkPesticide.Checked = False
chkPPE.Checked = False
chkReportInjuryIllnessDeath.Checked = False
chkSafetyPolicyProcedure.Checked = False
chkSanitation.Checked = False
chkSexualHarassment.Checked = False
chkSlipsTripsFalls.Checked = False
chkTransportation.Checked = False
chkTreeWorkPruningOperations.Checked = False
chkUseTools.Checked = False
Dim dsTrainingItems As New DataSet
Dim dtTrainingItems As New DataTable
dsTrainingItems.Tables.Add(dtTrainingItems)
Dim daTrainingItems As New OleDb.OleDbDataAdapter("SELECT * FROM tblTrainingItems WHERE ID = " & txtTrainingID.Text, con)
daTrainingItems.Fill(dtTrainingItems)
Try
If dsTrainingItems.Tables("TrainingItems").Rows(inc).Item("Sanitation") = 1 Then
chkSanitation.Checked = True
End If
If dsTrainingItems.Tables("TrainingItems").Rows(inc).Item("Pesticides") = 1 Then
chkPesticide.Checked = True
End If
If dsTrainingItems.Tables("TrainingItems").Rows(inc).Item("UseOfTools") = 1 Then
chkUseTools.Checked = True
End If
If dsTrainingItems.Tables("TrainingItems").Rows(inc).Item("LiftingItems") = 1 Then
chkLiftingItems.Checked = True
End If
If dsTrainingItems.Tables("TrainingItems").Rows(inc).Item("ElectricalSafety") = 1 Then
chkElectricalSafety.Checked = True
End If
If dsTrainingItems.Tables("TrainingItems").Rows(inc).Item("SafetyPolicyProcedure") = 1 Then
chkSafetyPolicyProcedure.Checked = True
End If
If dsTrainingItems.Tables("TrainingItems").Rows(inc).Item("ReportingInjuriesIllnessDeath") = 1 Then
chkReportInjuryIllnessDeath.Checked = True
End If
If dsTrainingItems.Tables("TrainingItems").Rows(inc).Item("TreeWorkPruningOperations") = 1 Then
chkTreeWorkPruningOperations.Checked = True
End If
If dsTrainingItems.Tables("TrainingItems").Rows(inc).Item("HeatStress") = 1 Then
chkHeatStress.Checked = True
End If
If dsTrainingItems.Tables("TrainingItems").Rows(inc).Item("OperatingEquipInspection") = 1 Then
chkOperatingEquipInspection.Checked = True
End If
If dsTrainingItems.Tables("TrainingItems").Rows(inc).Item("FirstAid") = 1 Then
chkFirstAid.Checked = True
End If
If dsTrainingItems.Tables("TrainingItems").Rows(inc).Item("Transportation") = 1 Then
chkTransportation.Checked = True
End If
If dsTrainingItems.Tables("TrainingItems").Rows(inc).Item("SexualHarrassment") = 1 Then
chkSexualHarassment.Checked = True
End If
If dsTrainingItems.Tables("TrainingItems").Rows(inc).Item("GlobalGap") = 1 Then
chkGlobalGap.Checked = True
End If
If dsTrainingItems.Tables("TrainingItems").Rows(inc).Item("ForkliftTraining") = 1 Then
chkForkliftTraining.Checked = True
End If
If dsTrainingItems.Tables("TrainingItems").Rows(inc).Item("EmergencyResponse") = 1 Then
chkEmergencyResponse.Checked = True
End If
If dsTrainingItems.Tables("TrainingItems").Rows(inc).Item("SlipsTripsFalls") = 1 Then
chkSlipsTripsFalls.Checked = True
End If
If dsTrainingItems.Tables("TrainingItems").Rows(inc).Item("LadderSafety") = 1 Then
chkLadderSafety.Checked = True
End If
If dsTrainingItems.Tables("TrainingItems").Rows(inc).Item("PPE") = 1 Then
chkPPE.Checked = True
End If
If dsTrainingItems.Tables("TrainingItems").Rows(inc).Item("DrugAlcoholPolicy") = 1 Then
chkDrugAlcoholPolicy.Checked = True
End If
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
So to troubleshoot, I add a DataGridView to the form, comment out all the chkBoxes and insert:
DataGridView1.DataSource = dtTrainingItems.DefaultView
and it loads the querried data just fine.
Sooooo I'm confused. And sober. Anyone know any good rum?