The creation and customization of database applications using Microsoft Access
@Ken Sheridan
Sorry for so many responses here.. I was able to fix the issue of not adding new records with each search. I noticed that the second subform on the parent form autofills, but with one Header SN (text box field on subform 1), there will be many records in subform 2. How do I make the subform 2 not fill? I was planning to have a search button on that subform as well to be able to search by a serial number there.
I have edited my code a bit (see below). I changed the text box to not have an equation that equaled the bound box for a SN, as I think this was making it so every time I clicked the search button a new record was added to the subform table. I have also made it so the bookmark action (from your on current event) is within the button click event (text box and button on subform), but I still cannot get the subform fields to fill. The parent form fills just fine. What am I doing wrong?
Private Sub Search_SN_Button_Click()
Const MESSAGETEXT = "No matching records found."
Dim ctrl As Control
Dim strFilter As String
Dim rs As DAO.Recordset
Set ctrl = Me.[Header SN Placeholder]
'Header SN Placeholder is not bound to the table, formula equals text entered in Header SN Field textbox on subform
strFilter = "[Furnace Run ID] IN(SELECT [Furnace Run ID] " & _
"FROM [Header Data] WHERE [Header SN] = """ & ctrl & """)"
If Nz(ctrl, 0) = 0 Then
' turn off filter
Me.Parent.FilterOn = False
Me.Parent.[Header Data Form].Form.FilterOn = False
Else
If Not IsNull(DLookup("[Header SN]", "[Header Data]", "[Header SN] = '" & ctrl & "'")) Then
' filter form to name selected in text box
Me.Parent.Filter = strFilter
Me.Parent.FilterOn = True
' filter subform to selected Header SN
'Me.[Parent].[Header Data Form].[Form].Filter = "[Header SN] = '" & ctrl & "'"
'Me.[Parent].[Header Data Form].[Form].FilterOn = True
Else
If Not IsNull(Me.[Header SN Placeholder]) Then
With Me.[Header Data Form].Form
.RecordsetClone.FindFirst "[Header SN] = " & Me.[Header SN Placeholder]
If Not .RecordsetClone.NoMatch Then
.Bookmark = .RecordsetClone.Bookmark
End If
End With
End If
End If
End If
If IsNull(DLookup("[Header SN]", "[Header Data]", "[Header SN] = '" & ctrl & "'")) Then
' inform user if no matching records found
MsgBox "Sorry, no such record '" & [Header SN Placeholder] & "' was found.", _
vbOKOnly + vbInformation
End If
End Sub