Link to home
Start Free TrialLog in
Avatar of Ed Walsh
Ed WalshFlag for United States of America

asked on

Tracking Logins In CR 8

I have a table that tracks the logins of users to a website.  They login and the table captures there:
[UserID], [Logindate] (Userid is numeric & the Logindate field has both date and time in it).

For a project I need to count how many times a person logged in for a date range, Usually a monthly range, however there is a catch, if the person logs in again and its less than 60 minutes since the last time they logged in, it should only count as 1 login.

I figure I could group by [Userid] and sort the [Logindate] field in Ascending order and create a Formula field that has a "If Then Else" that looks at the current [Logindate]field in the record and compares it to the [Logindate] field in the previous record and if its less than 60 minutes make the Formula field = 0 and if not it = 1, then do a Sum on this field and I should have my problem solved!  However how do I compare against a previous record? Is there a function for this?

P.S. I am using Crystal reports 8 But I also have access to CR 8.5 if needed!
Avatar of DRRYAN3
DRRYAN3

EWalsh

Use the PreviousValue({fieldname}) function.  Example to follow in a second.
Sorry, gave you wrong syntax

Try something like this

dateTimeVar OldDate := Previous({logins.logindate});
dateTimeVar CurDate := {logins.loginddate};
stringVar OldLogin := Previous({logins.userid});
stringvar CurLogin := {logins.userid};

if OnFirstRecord or PreviousIsNull({logins.userid}) then
1
else
if OldLogin <> CurLogin then
  1
else
if datediff("n", OldDate, CurDate) > 60 then
1
else
0
Avatar of Ed Walsh

ASKER

Ok, It looks like this works, But know there is a new problem, I cant SUM up on this formula field!
It doesnt list it as a filed in the "Insert Summary"
Or if I try to make a Running Total Field!
I made another formula field that simply showed 1 if it = a specific company name else 0.  And that Formula field WOULD allow me to create a summary or a running total field.
But then I CUt/Copied the original into this test field and then I couldn't use it again!  VERY ODD!!!
I tell you as powerful as CR is I sometimes hate it,  MS Access is so much easier when it comes to this stuff!

P.S.  I tried this on 2 diff machines one running CR 8  the other running CR 8.5
It seems that if I omit any refrence to Previous()  it will allow to SUM up, But enter a Previous() Function and NO DICE!!!
I am using Crystal Syntex
ewalsh

This would be fairly trivial if you could use VB as a front end to the Crystal Report.  Is that a possibility?
I'm afraid not.  However, in VBA is there a Previous() Function equivalnt?  If so I'd do it in MS Access.
You don't need a previous function.  Build a temp table in Access by using a recordset object to step through your logins table in loginid/date order.  As you step through the original table, compare the login/date time to the previous one that you'll keep in a variable.  A psuedo process to do this...

dim oLogindate as datetime
dim oLoginID as long
Open recordset for original file
Open empty recordset for temp file
oLoginDate = #01/01/1980#
oLoginID = originalrecordset!loginid
while not at end of recordset
  if datediff('n',oLoginDate, recordset!logindate) > 60 OR oLoginID <> originalrecordset!loginid then
  temprecordset.addnew
  temprecordset!loginid = orginalrecordset!loginid
  temprecordset!logindate = originalrecordset!logindate
  temprecordset.update
  end if
  oLoginDate = originalrecordset!logindate
  oLoginID = originalrecordset!loginID
  originalrecordset.movenext
loop

This should give you a table in your temp table that contains only one record for any given user within any 60 minute period.  Base your report off the temp table.

Sorry about the sloppy code - I don't have Access at home - but this will get you going.
Well looks like this is a problem within CR (all version up to 8.5)  Wrote to CR's tech support and this was there reply.
------------------------------

To resolve your issue you should change your IF statement.

Whileprintingrecords;
Numbervar Counter;
not onfirstrecord;
if datediff ("n", previous
({LOGINRECORD.LOGINDATE}),{LOGINRECORD.LOGINDATE}) > 60 then
Counter := Counter + 1


This will give you a count for you. However this is not the only formula you will need.
You will need a reset formula for the variable "Counter" in the Group Header that you would like it to reset in. One more to display it. This is referred to as a Manual Running Total and this will be your only option
due to the point of evaluation when using the previous function.

For further information on Manual Running Totals, you can search:
http://support.crystaldecisions.com   for Everything You Need to know
about running Totals. Or http://support.crystaldecisions.com/library/ 
search: scr_running_total.zip


Kind regards,
Chad
Tech 909
EWalsh

Been away for awhile.  If you want to close the question without awarding points, leave a message in community support asking them to PAQ this question.

DRRYAN3
EWalsh

If you want to close the question without awarding points, leave a message in community support asking them to PAQ this question.

DRRYAN3
ASKER CERTIFIED SOLUTION
Avatar of DRRYAN3
DRRYAN3

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Force Accepted by:
Moondancer
Community Support Moderator @ Experts Exchange