WHERE in SQL

radek225

Registered User.
Local time
Today, 11:02
Joined
Apr 4, 2013
Messages
307
I want to find field "id_zlecenia" - autonumber where field "DataPrzyjecia" - Date is youngest in table "tblZlecenia", I have a problem with WHERE, I know that, should use "#" for a date field, but I don't know how to write it.
Function - I think MAX will be ok.

Code:
Dim sSQL As String
Dim rst As Recordset
sSQL = "SELECT id_zlecenia FROM tblZlecenia [COLOR="Red"]WHERE...[/COLOR] "
Set rst = CurrentDb.OpenRecordset(sSQL)
Me.Tekst1 = rst!ID_Zlecenia


rst.Close: Set rst = Nothing
 
I have Two types of ID in my tbl. First (key) "id" - autonumber, and another "id_zlecenia" (relic of paper orders). "id_zlecenia" e.g. "171/14" (number as of this present year/ two last numbers of year), Find youngest date will help me find last "id_zlecenia" then I can create next "id_zlecenia" automatically, using another code.
 
So it could be something like
Code:
Dim sSQL As String
Dim rst As Recordset
sSQL = "SELECT id_zlecenia FROM tblZlecenia WHERE DataPrzyjecia = Max(Dataprzyjecia) as LastDate"
Set rst = CurrentDb.OpenRecordset(sSQL)
Me.Tekst1 = rst!ID_Zlecenia


rst.Close: Set rst = Nothing

But how to write it correctly :/?
 

Users who are viewing this thread

Back
Top Bottom