WindSailor
Registered User.
- Local time
- Yesterday, 22:23
- Joined
- Oct 29, 2003
- Messages
- 239
Hi all,
Lately I have been having problems with SQL statements using the ‘Distinct’ keyword.
The following code below in the SQLText2 statement has fictitious Table and Column names but the structure is the same.
Dim db1 As DAO.Database
Dim rst00 As DAO.Recordset
Dim db12 As DAO.Database
Dim rst01 As DAO.Recordset
Set db1 = CurrentDb
Set db12 = CurrentDb
‘OK… I first run a simple SELECT statement, Set rst00 = db1.OpenRecordset(SQLText1), find first, move next, (which works fine) and then if rst00 is End Of File then do the following…
SQLText2 = SELECT DISTINCT
FullN, Price1, Weight1, Palete1
FROM OrderDetails
INNER JOIN OrderPalettes
ON
OrderDetails . Palette1 = OrderPalettes .PaletteCoreLookUPNumber
AND
OrderDetails . Price1 = OrderPalettes .PriceCoreLookUPNumber
ORDER BY Price1,Weight1 ASC
Set rst01 = db12.OpenRecordset(SQLText2)
When I use the SQL scratchpad from the Access 2002 Developers Handbook to test my SQL statements inside my database, the above SQL statement works fine; but when I use it inside my project on a form, it doesn’t return any records or it doesn’t return the values correctly. I simply have tried so many different variations using the DISTINCT keyword that I have forgotten the original error with the above statement. It is just that I couldn’t get it to work correctly and simply went back and trapped for duplicates without using the DISTINCT keyword.
The only thing I can think of currently is that my structure is wrong, or Access 2003 doesn’t really like the DISTINCT keyword.
Any tips are greatly appreciated.
Lately I have been having problems with SQL statements using the ‘Distinct’ keyword.
The following code below in the SQLText2 statement has fictitious Table and Column names but the structure is the same.
Dim db1 As DAO.Database
Dim rst00 As DAO.Recordset
Dim db12 As DAO.Database
Dim rst01 As DAO.Recordset
Set db1 = CurrentDb
Set db12 = CurrentDb
‘OK… I first run a simple SELECT statement, Set rst00 = db1.OpenRecordset(SQLText1), find first, move next, (which works fine) and then if rst00 is End Of File then do the following…
SQLText2 = SELECT DISTINCT
FullN, Price1, Weight1, Palete1
FROM OrderDetails
INNER JOIN OrderPalettes
ON
OrderDetails . Palette1 = OrderPalettes .PaletteCoreLookUPNumber
AND
OrderDetails . Price1 = OrderPalettes .PriceCoreLookUPNumber
ORDER BY Price1,Weight1 ASC
Set rst01 = db12.OpenRecordset(SQLText2)
When I use the SQL scratchpad from the Access 2002 Developers Handbook to test my SQL statements inside my database, the above SQL statement works fine; but when I use it inside my project on a form, it doesn’t return any records or it doesn’t return the values correctly. I simply have tried so many different variations using the DISTINCT keyword that I have forgotten the original error with the above statement. It is just that I couldn’t get it to work correctly and simply went back and trapped for duplicates without using the DISTINCT keyword.
The only thing I can think of currently is that my structure is wrong, or Access 2003 doesn’t really like the DISTINCT keyword.
Any tips are greatly appreciated.