firefly2k8
Registered User.
- Local time
- Today, 12:56
- Joined
- Nov 18, 2010
- Messages
- 48
I have the following code. It creates an identifier with String1&Date1, then gets all unique records. Then creates an identifier with String2&Date1, and gets all unique records. Then again with String3&Date1. I use Union to stack them all together. But then i want to make sure that there are no duplicates in the result and I want to query it again.
Unfortunately it wont let me do rst1.Open strSQL2. So how do I query the result of the query? I will also want to permanently store the result of this query in a new table.
Thanks for your help as always.
Unfortunately it wont let me do rst1.Open strSQL2. So how do I query the result of the query? I will also want to permanently store the result of this query in a new table.
Thanks for your help as always.
Code:
Sub test3()
Dim strSQL, strSQL2 As String
Dim rst1 As ADODB.Recordset
Dim fld1 As Field
Dim int1 As Integer
strSQL = "SELECT DISTINCT [String1] & [Date1] AS Expr1 " & _
"FROM [Project Table 1] " & _
"WHERE [String1] is not null " & _
"UNION " & _
"SELECT DISTINCT [String2] & [Date2] AS Expr1 " & _
"FROM [Project Table 1] " & _
"WHERE [String2] is not null " & _
"UNION " & _
"SELECT DISTINCT [String3] & [Date3] AS Expr1 " & _
"FROM [Project Table 1] " & _
"WHERE [String3] is not null ;"
strSQL2 = "SELECT DISTINCT [Expr1] as Expr1 " & _
"FROM [rst1]"
Set rst1 = New ADODB.Recordset
rst1.ActiveConnection = "FILEPATH;"
rst1.Open strSQL
Debug.Print rst1.RecordCount
rst1.Open strSQL2
Debug.Print rst1.RecordCount
rst1.Close
Set rst1 = Nothing
End Sub