Re: Refer to the first row of the table
- From: "samotek via AccessMonster.com" <u15330@uwe>
- Date: Fri, 17 Aug 2007 04:10:08 GMT
Thank you so much indeed ! Your line of code which i think is very clever,
gives me a syntax error and i must have written something wrong somewhere.
Would you have a look :
Syntax error in query expression 'afid >SELECT Min(T.afid) FROM TblClients1
As T)'
Public Function str()
Dim StrSQL As String
StrSQL = " DELETE * FROM TblClients1 WHERE afid > SELECT Min(T.afid) FROM
TblClients1 As T)"
CurrentDb.Execute StrSQL
End Function
Dirk Goldgar wrote:
Thank you so much indeed. You are right in what you guesed,i just[quoted text clipped - 32 lines]
didnt see that i have no field named "WhenCreated" and i thought this
Syntax error in query expression "TblClients1.afid Not FirstAfid"
Although your SQL statement could be simplified, there are two main
errors in it. First, you need to use the "<>" ("not equal") operator
instead of just "NOT". Second, you need to embed the *value* of
FirstAfid in the SQL string, not the variable name. Aside from those
errors, remember that you don't want to do this unless you actually
found a value for FirstAfid. So I would amend your code like this:
'---- start of revised section of code ----
With rs
If .EOF Then
MsgBox "No records!"
ElseIf IsNull(!afid) Then
MsgBox "No afid in first record!"
Else
FirstAfid = !afid
StrSQL = _
"DELETE * FROM TblClients1 WHERE afid <> " & FirstAfid
CurrentDb.Execute StrSQL, dbFailOnError
End If
.Close
End With
'---- end of revised section of code ----
Now that you've made it clear that you want to order by afid, and only
want to keep the records with the lowest afid, the whole process could
be simplified to a single delete query:
DELETE * FROM TblClients1
WHERE afid >
(SELECT Min(T.afid) FROM TblClients1 As T)
That statement uses a subquery to find out the lowest afid value, and
then deletes all records with afid greater than that value. I haven't
tested the SQL, but something along those lines ought to work.
--
Message posted via http://www.accessmonster.com
.
- Follow-Ups:
- Re: Refer to the first row of the table
- From: Dirk Goldgar
- Re: Refer to the first row of the table
- References:
- Refer to the first row of the table
- From: samotek via AccessMonster.com
- Re: Refer to the first row of the table
- From: Dirk Goldgar
- Re: Refer to the first row of the table
- From: samotek via AccessMonster.com
- Re: Refer to the first row of the table
- From: Dirk Goldgar
- Re: Refer to the first row of the table
- From: samotek via AccessMonster.com
- Re: Refer to the first row of the table
- From: Dirk Goldgar
- Refer to the first row of the table
- Prev by Date: RE: Multi user database
- Next by Date: MS Access 2000 VB HELP!
- Previous by thread: Re: Refer to the first row of the table
- Next by thread: Re: Refer to the first row of the table
- Index(es):
Relevant Pages
|