Hi
I have a form called filter which has some textboxes on it. Also in the form I have a subform called "View_Contacts_subform" This is bound to a table called "Contacts" The subform has the following fields: FirstName, LastName, Company, County, Category.
I am using my filter form to filter the subform which works great it shows what I want to see. However I want to be able to save these results into a table which will be overwritten each time. This table will then be used to email them and make emails. If possible I would also like to include a checkbox which the user can untick if they do not want them to be used to it is removed from the table. The table I want all this information to be stored on is called "Filter_Results"
I have tried using a SQL statement to do this, however it only adds one record not all of them that are showing on the form. For example I have 5 records. I filter the records down to A and B. When it saves them to the table it only saves record A not B. I am only saving the FirstName for now because that is easier for me to work with then I will add the other fields.
I was thinking is there a way to count the number of records then loop though each one, that is beyond me, here is my code on the "Search" button on my Filter_Contacts form which holds the subform
Code:Dim strWhere As String Dim lngLen As Long If Not IsNull(Me.s_PostalCode) Then strWhere = strWhere & "([PostalCode] = """ & s_PostalCode & """) AND " End If If Not IsNull(Me.s_Company) Then strWhere = strWhere & "([Company] Like ""*" & Me.s_Company & "*"") AND " End If If Not IsNull(Me.s_County) Then strWhere = strWhere & "([County] Like ""*" & Me.s_County & "*"") AND " End If If Not IsNull(Me.CategoryList) Then strWhere = strWhere & "([Category] Like ""*" & Me.CategoryList & "*"") AND " End If If Me.AGM = -1 Then strWhere = strWhere & "([AGM] = true) AND " End If If Me.s_Newsletter = -1 Then strWhere = strWhere & "([Newsletter] = true) AND " End If lngLen = Len(strWhere) - 5 If lngLen <= 0 Then MsgBox "No criteria", vbInformation, "Nothing to do." Else strWhere = Left$(strWhere, lngLen) Me.View_Contacts_subform.Form.Filter = strWhere Me.View_Contacts_subform.Form.FilterOn = True End If Dim MySQL As String MySQL = "INSERT INTO Filter_Results (FirstName) SELECT [Forms]![Filter_Contacts]![View_Contacts_subform].[Form]![FirstName] AS FirstName;" DoCmd.RunSQL MySQL