Assume the following:
(Disregard the bad sql syntax in "create table" segments, I'm simplifying the message for better understanding)
Create table Event_Participants (
Event_Name, text
Event_Participant, text
Event_Participant_Arrival, date/time
Event_Participant_Leaving date/time
)
There is no PK, only an index on Event_Name and Event_Participant to make sure no Participant can be logged more than once for one Event.
Assume, also
Create table Events (
Event_Name, text
Event_Start_Time, date/time
Event_End_Time, date/time
)
Again, no PK: Only Event_Name is a unique index
date1=[Query to get a participant particular arrival time for Event1]
date2=[Query to get Event1's particular Start_Time] (As you might've noticed, date2 is singular)
I want to run an update query and change some data with it, based on multiple conditions, wherein I only got stuck on the following
where DateDiff("n",date1,date2)<0
(This particular condition should check if anyone is late).
What I'm stuck with, is, how to do this date/time differential in minutes for all participants?
I can make it work when date1 is a single row, but on multiple, it says the "can fetch maximum one row" or something of the sort.
Dim rs As DAO.Recordset
Dim qry, points, pp As String
Dim pts As Integer
pp = Me.Form.cbo_query_picker.Value
Set rs = CurrentDb.OpenRecordset("SELECT DateDiff('n',IIf([Arrival Date]<=(SELECT Start_Date FROM Events WHERE Descriptive_Name='" & pp & "'),(SELECT Start_Date FROM Events WHERE Descriptive_Name='" & pp & "'),[Arrival Date]),IIf([Quitting Date]>=(SELECT End_Date FROM Events WHERE Descriptive_Name='" & pp & "'),(SELECT End_Date FROM Events WHERE Descriptive_Name='" & pp & "'),[Quitting Date])) AS pts, Event_Participants.Participant, Event_Participants.[Event Name] FROM Event_Participants")
rs.MoveFirst
Do Until rs.EOF = True
pts = Int(rs("pts").Value / 30) * 3
qry = "update customers set points = points + "
qry = qry & Format(pts, "0")
qry = qry & " where [Customer name] = '"
qry = qry & rs("Participant") & "'"
CurrentDb.Execute (qry)
Debug.Print qry
rs.MoveNext
Loop
rs.Close
This is the VBA code I finally scrambled together to make the access work as any sql standard dialect would. While I acknowledge the answer by @Wolfgang Kais I got my problem solved through VBA instead, and would appreciate any suggestion, how to make this more, elegant. I feel this code can be improved to look better, but don't know how for now.