Hello,
I’m basically attempting to lookup values from one table (from multiple records) and insert them into one record in another table. I’ve attempted to do this with dlookups and dmaxs (which pick up exactly what I want) and using an SQL statement to insert them into another table. My code is below.
Sub Instance()
Dim offtime As Date
Dim userdatetime As Date
Dim userdate As Date
Dim userevent As String
Dim userid As Single
Dim prevuserdatetime As Date
Dim rawtime As Single
userid = DMax("ID", "Q_syslog")
userdatetime = DLookup("convdatetime", "q_syslog", "id=" & userid)
userevent = DLookup("event", "Q_syslog", "id=" & userid)
prevuserdatetime = DLookup("convdatetime", "q_syslog", "id=" & userid - 1)
rawtime = (DateDiff("s", prevuserdatetime, userdatetime)) / 86400
offtime = Format(rawtime, "HH:MM:SS")
InstanceID = Nz(DMax("Instance", "Instance"), 0) + 1
DoCmd.RunSQL "INSERT INTO Instance ([Instance], [Logout], [Login],[Event],stoppagetime) VALUES (Instanceid, prevuserdatetime,userdatetime,userevent,offtime);"
I was aware I might have issues due to compatibility issues with the dlookups and the SQL statement. The dlookups work, and the insert statement works, but not with each other! When it inserts it treats the values as blank parameters.
Any suggestions would be great,
Thanks
I’m basically attempting to lookup values from one table (from multiple records) and insert them into one record in another table. I’ve attempted to do this with dlookups and dmaxs (which pick up exactly what I want) and using an SQL statement to insert them into another table. My code is below.
Sub Instance()
Dim offtime As Date
Dim userdatetime As Date
Dim userdate As Date
Dim userevent As String
Dim userid As Single
Dim prevuserdatetime As Date
Dim rawtime As Single
userid = DMax("ID", "Q_syslog")
userdatetime = DLookup("convdatetime", "q_syslog", "id=" & userid)
userevent = DLookup("event", "Q_syslog", "id=" & userid)
prevuserdatetime = DLookup("convdatetime", "q_syslog", "id=" & userid - 1)
rawtime = (DateDiff("s", prevuserdatetime, userdatetime)) / 86400
offtime = Format(rawtime, "HH:MM:SS")
InstanceID = Nz(DMax("Instance", "Instance"), 0) + 1
DoCmd.RunSQL "INSERT INTO Instance ([Instance], [Logout], [Login],[Event],stoppagetime) VALUES (Instanceid, prevuserdatetime,userdatetime,userevent,offtime);"
I was aware I might have issues due to compatibility issues with the dlookups and the SQL statement. The dlookups work, and the insert statement works, but not with each other! When it inserts it treats the values as blank parameters.
Any suggestions would be great,
Thanks