Indenting code does help with readibility.
The cmdOpenChecklist code only executes a macro that makes subform visible. Could be all VBA with:
Me.frmChecklist.Visible = True
I still don't see implemented code that creates a complete set of checklist records for a piece of equipment. I did find Sub txtTest where you have my suggested code and I see the query I formed. Now the dilemma is where to put this code. I would think in cmdOpenChecklist, just before the line that makes the subform visible. Something like:
Code:
Private Sub cmdOpenChecklist_Click()
Dim x As Integer
If IsNull(DLookup("InspectionID", "qryChecklistAnswer", "InspectionID=" & Me.InspectionID & " AND EquipmentID=" & Me.EquipmentID)) Then
x = Nz(DMax("InspectionID", "qryChecklistAnswer", "EquipmentID=" & Me.EquipmentID),0)
If x <> 0 Then
DoCmd.SetWarnings False
DoCmd.RunSQL "INSERT INTO qryChecklistAnswer (InspectionID, EquipmentID, ChecklistID, AnswerID) SELECT " & Me!InspectionID & " AS InspectionID, EquipmentID, ChecklistID, AnswerID FROM qryChecklistAnswer WHERE InspectionID =" & x & " AND EquipmentID=" & Me!EquipmentID
DoCmd.SetWarnings True
Me.frmChecklist.Requery
Else
MsgBox "No prior inspection for this equipment."
End If
End If
Me.frmChecklist.Visible = True
End Sub