Results 1 to 8 of 8
  1. #1
    weeblesue is offline Novice
    Windows XP Access 2007
    Join Date
    Oct 2010
    Location
    Houston, TX
    Posts
    14

    Question How do I find another row in my same query/table where RowX.text = MyRow.text?

    I have an Access Database to store my software license usage data and provide reports. The license manager is proprietary and has no reporting features whatsoever.



    I import the data from the vendor log file:
    User UserGroup UniqueIdentifierCookie Action Module DateTimeStamp
    userid region text string of numbers CheckOut or CheckIn ModuleUsed [obvious]

    The software assigns a unique identifier (called a cookie, not really a cookie as we know it from web browsers) when the user opens a module and takes a license. This is recorded with which module is used, and of course a date/time stamp. When the user checks in that license, the cookie is repeated with CheckIn as the action and another date/time stamp. So each step gets a separate line in the code.

    I load the table as a recordset, and if the action is "checkout" then i read the cookie.

    Here's where i get lost. I need to find the corresponding row in this same query where the cookie is the same, and read the timestamp from that row. Only right now, there are over 41,000 entries in this table and i don't want to have to cycle through 40,000 rows looking for whether the cookie matches. The table is only going to grow. The CheckIn data is typically well within 100 rows of the CheckOut data.

    Once i read the checkin timestamp, i can manage the delta time.

    but here's tricky part #2. i want to put the resultant delta time value in the row with the CheckIn, not the CheckOut.

    How do I determine the row number of the CheckIn Data so i can put the delta time there?

    I can accomplish this in Excel, but the file is HUGE and takes forever to load, filter, sort, save, etc (and i have calculation on Manual). Access is a much better place to do this, but i can't figure out this action.

    I have searched this forum and found code that will loop me through the entire table, row by row, but I get stuck at the "find record" entry. From what I'm reading, FindRecord might not be what i need to use here.
    Code:
    Public Sub CalculateDelta()
    Dim sSQL As String
    Dim db As DAO.Database
    Dim rs As DAO.Recordset
    Dim td As DAO.TableDef
    Dim f As DAO.Field
    On Error Resume Next
    Set rst = CurrentDb.OpenRecordset("SELECT Cookie, Action, FinalDateTime, Delta FROM [Users Log Query02] ")
    ' From Users Log Query02, get Cookie, Action, FinalDateTime.
    ' This is already sorted by Module.
    If Not (rst.EOF And rst.BOF) Then
        rst.MoveFirst
        Do Until rst.EOF = True
        TDelta = rst!Delta
        
        If TDelta Is Nothing Then
        ' Only need to run if there is no delta value already
        
        strAction = rst!Action
        
        If strAction = "CHECKOUT" Then
     
            ' Store Cookie as string
            strCookie = rst!Cookie
        
        'DoCmd.FindNext where Cookie = CookieString and Action = CHECKIN.???
        ' Get FinalDateTime of this record.
        ' DeltaTime = FinalDate2 - FinalDate1
        
        ' Place DeltaTime into blank Delta CHECKIN column.
          
            'Move to the next record.
            rst.MoveNext
        Loop
    Else
        MsgBox "There are no records in the recordset."
    End If
    rst.Close
    End Sub
    Can someone suggest what direction I should try?

    Thanks...
    Susan

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    What's the final goal of all this? If every cookie will have two records, a simple totals query can give you the two times. Given your process, the direct answer to your question is that you could open a second recordset inside the loop to find the corresponding check in, or perhaps simpler a DLookup().
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    weeblesue is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2010
    Location
    Houston, TX
    Posts
    14
    The goal is to have the amount of time used by that user for that instance. CheckIn time - CheckOut time. But that can't be just a temporary value. I need it placed in a table or query somewhere, because i need to run several types of reports using those values, and i do not want to have to recalculate it each time.
    Sample report types: weekly by user, weekly by group/region, weekly by module, monthly by each, user-specified date range by user/group/module, admin vs regular user, etc. The manager needs to be able to click on a report and get a result quickly, and an intermediate result would not provide that.

    I will try a totals query. That just may be the shortcut that i have been looking for. Thanks!

  4. #4
    weeblesue is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2010
    Location
    Houston, TX
    Posts
    14
    Nope, a total query isn't going to work. There's no subtraction function for such a query.

    I cannot add 45678 and 45789 and get the delta between the 2 values.

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Really? This doesn't work?

    SELECT Cookie, Min(FinalDateTime) As StartTime, Max(FinalDateTime) As EndTime, Max(FinalDateTime)-Min(FinalDateTime) As ElapsedTime
    FROM [Users Log Query02]
    GROUP BY Cookie

    If not, can you provide a sample db with data to play with?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    weeblesue is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2010
    Location
    Houston, TX
    Posts
    14
    Your solution works! I got stuck thinking I couldn't refer to two different rows in the same line of the query. It's all in the way it's grouped!

    Thank you, thank you, thank you!!

  7. #7
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Happy to help!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  8. #8
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Two incidental things:

    Not really germane, now, but you should know, for future reference

    where RowX.text = MyRow.text

    The Text Property is only available when a Control on a Form has Focus, and hence is seldom used in Access. The Text Property doesn't necessarily give the value of the given Field, but rather the data that is displayed in the Control when it has Focus.

    If, for instance, you go to an existing Record, and

    ControlX currently is ABC

    then ControlX.Value = ABC.

    If you enter ControlX (give it Focus) and enter XYZ, leaving the cursor in the Control, then

    ControlX.Value = ABC

    but

    ControlX.Text = XYZ !

    Quote Originally Posted by weeblesue View Post

    ...i need to run several types of reports using those values, and i do not want to have to recalculate it each time...
    Re-calculating Fields, when needed, is considered 'best practice' by every experienced Access developer that I'm acquainted with. In addition to the fact that you're unnecessarily storing data, the experts in this sort of thing will tell you this type of re-calculation, done later in a Query, Report or other Form will take less time than retrieving the piece of data! Also, there are conditions where either CheckIn time or CheckOut time could be modified but the calculation not run and stored, so the value would not be correct. Re-calculating, when needed, would avoid this problem.

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Find records using combo box and text box
    By ihaveaquestion in forum Forms
    Replies: 1
    Last Post: 10-02-2013, 02:53 PM
  2. Replies: 3
    Last Post: 02-07-2013, 09:53 PM
  3. Trying to find a value right of specific string with in text
    By weilerda in forum Import/Export Data
    Replies: 2
    Last Post: 10-18-2012, 12:58 PM
  4. find all text string in Criteria at once
    By Jerseynjphillypa in forum Queries
    Replies: 3
    Last Post: 05-15-2012, 12:12 PM
  5. Replies: 0
    Last Post: 03-01-2010, 07:42 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums