VBA delete with dlookup Error 1 expected :( (1 Viewer)

ahmed_optom

Registered User.
Local time
Today, 09:04
Joined
Oct 27, 2016
Messages
93
Im trying to delete a record from a table.

Currently gives a runtime 3061 error, Too few parameters, 1 expected.

Here is the offending code


sql = "DELETE * FROM [Diary] WHERE [ID]= Dlookup([ID],[Diary],[AppointmentDate]='#[me].[Text13]#' and [SlotNumber]=2)"
CurrentDb.Execute sql


Im trying to find the appointment in table "Diary", which has an ID, which is identified by finding a certain date stored in text13 and Slot number, in this case "2".


Any ideas?
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 16:04
Joined
May 7, 2009
Messages
19,233
dim id as Long
id = Nz(Dlookup("[ID]","[Diary]","[AppointmentDate]=#" & Format(me.[Text13],"mm\/dd\/yyyy") & "# and [SlotNumber]=2"), 0)
sql = "DELETE * FROM [Diary] WHERE [ID]=" & id
 

ahmed_optom

Registered User.
Local time
Today, 09:04
Joined
Oct 27, 2016
Messages
93
Thanks Arnelgp.

That edit fixed it.

If your ever in the UK, let me know and I owe you a drink.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 16:04
Joined
May 7, 2009
Messages
19,233
tnx but im not from UK.
and I don't drink... when there is no videoke!
 

Users who are viewing this thread

Top Bottom