Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with a query

Status
Not open for further replies.

phyllisk

Technical User
Jul 23, 2001
11
GB
I wonder if anyone can help me, as I am not very with good with SQL Statements.
I want to use a make table query based on my main table for constant mail merge data. This data is then dependent of Filter by Form from the main table.

When I want to run the Make Table query on my form that I have applied a filter to. For example, I have filtered off 43 records from a total of 413, the make table query produces the total records and not the filtered amount.
Is this because I need a SQL statement inside my Make Table query stating the FilterOn? and if so, how do I do this?

many thanks in advance.
 
You'll have to use a little VBA code, here it is. Note- For the second piece of code you will need to attach it to an event on your form, such as a button click....

Sub FilteredTable(strTable As String, strFilter As String, strNewTable As String)

Dim strSQL As String

strSQL = "SELECT * INTO " & strNewTable & " FROM " & strTable & " WHERE " & strFilter

CurrentDb.Execute strSQL

End Sub

Private Sub [Some Buttons Name]_Click(Cancel As Integer)

Dim strNewTable As String

strNewTable = InputBox("What Is The Name Of The Table To Be Created?", "Make Table From Current Filter")

FilteredTable Me.RecordSource, Me.Filter, strNewTable

End Sub


You could also change it so that there is a field on the form for the new table name instead of the input box. Whatever works for you. Good Luck!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top