Results 1 to 18 of 18

Thread: Updating records

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2005
    Posts
    163

    Updating records

    Please have a look at http://www.asgsoft.net/form.xls

    You will see that there is a sheet for records

    and also there is an input sheet. What i want is to be able to see that if the information entered has broken the record. However there are two types of measurements. There is time, so the smaller the better but there are also distance events so the longer that better.

    Do you think you can help me?

    Thank you

  2. #2
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950

    Re: Updating records

    With your current setup, it looks like you'll have to get every entry for a particular event first, in order to check time/distance in any case. But to check whether you want shortest or longest, you'll have to check at least the first letter of each event. If it's numeric - IsNumeric(Left(somecell, 1)) - then check time. Otherwise, check distance.
    If this was Access I'd set it up differently, but I know Access lots better than Excel.
    Of course, this won't work if you have a time event that begins with a letter, or a distance event that begins with a number, but I didn't see any in your example.
    Another option would be to either separate time/distance into 2 columns, or add a column with some type of identifying code - T and D, for instance.
    Tengo mas preguntas que contestas

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Feb 2005
    Posts
    163

    Re: Updating records

    I was thinking of using an IF statement that checks what event it is? and then I have two functions to check if a record is broken. One for lengths and the other for time. But what I have trouble with is to check that a record was broken.

  4. #4
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950

    Re: Updating records

    Sorry, don't know how to do that between sheets. Access yes, Excel no.
    Tengo mas preguntas que contestas

  5. #5
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Updating records

    You could perform a Sort based on user/time/ascending and then get the first record for that user and look at the cell value. Then do the same for distance with th eappropriate changes.

    In your calling code you will perform the first sort and check the value then again another call to sort with the next criteria and get its value. Then if the record is broken by one r oth then you can inform the user or ? Just reference the other sheet.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Feb 2005
    Posts
    163

    Re: Updating records

    But is there no way to check if the record is broken as it's being entered?

  7. #7
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Updating records

    yes if can be done, you would have to loop through all rows to compare the the result for each race type, as this entails searchin the whole sheet for each race type it might be better to put each race type into a named range, then you can just work with all rows within that named range

    pete

  8. #8
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Updating records

    You could list the records of whatever type is being entered on the form itself. Or even use a UserForm instead of a Sheet for record entry.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Feb 2005
    Posts
    163

    Re: Updating records

    Quote Originally Posted by westconn1
    yes if can be done, you would have to loop through all rows to compare the the result for each race type, as this entails searchin the whole sheet for each race type it might be better to put each race type into a named range, then you can just work with all rows within that named range

    pete
    can you please give me some code examples?
    Last edited by asgsoft; Jul 6th, 2006 at 01:05 PM.

  10. #10
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Updating records

    VB Code:
    1. Sub checkrecord()
    2. Dim s As Sheet4, f As Sheet1
    3. Set s = Sheet4
    4. Set f = Sheet1
    5. n = f.Name
    6. 's.Activate
    7. For i = 2 To s.UsedRange.Rows.Count
    8.     If s.Cells(i, 3) = f.Cells(3, 2) And s.Cells(i, 4) = f.Cells(4, 2) And s.Cells(i, 5) = f.Cells(6, 2) Then
    9.         If f.Cells(8, 2) > s.Cells(i, 6) Then 'compare time/distance, not sure if high or low is better
    10.             s.Cells(i, 2) = f.Cells(2, 2)      ' update record if better
    11.             s.Cells(i, 6) = f.Cells(8, 2)
    12.             s.Cells(i, 7) = Year(Now)
    13.            
    14.         End If
    15.         Exit For
    16.     End If
    17. Next
    18. 'for i = 1 to
    19.  
    20.  
    21.  
    22. End Sub

    try this see if it works right, check if i have the compare of time/distance round the right way, probably not, the code will just overwrite the new details into the rcords sheet

    pete

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Feb 2005
    Posts
    163

    Re: Updating records

    I don't have a Sheet4 or Sheet1

    Also how would you say I can check if the distance is more or time is less?

  12. #12
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Updating records

    you do have those sheets, cos i was working in your spreadsheet.

    sheet4 is the same as sheets(4) or sheets("records")

    which is faster, smaller time/distance or bigger??

    the code i posted checked if time distance was greater, then updated the record, if time/distance should be shorter to break record then change the greater than to less than.

    as it is for a particular event (eg. 100m) why not just record the time instead of time/distance?

    pete

  13. #13

    Thread Starter
    Addicted Member
    Join Date
    Feb 2005
    Posts
    163

    Re: Updating records

    OK its working, however, the time distance is a bit confusing. If it's a timed event such as 100m,200m,300m,400m,800m,1500m and relay then the shorter the time the better. Otherwise if its a distance event such as Shot,Discus,Javelin,High Jump,Long Jump,Triple Jump then the longer the distance the better.

    All the times are in seconds and distances are in centimeters so its easier to compare.

    How can I do this?

    When I try this I get an error:

    VB Code:
    1. Sub checkrecord2()
    2. Dim s As Sheet4, f As Sheet1
    3. Set s = Sheet4
    4. Set f = Sheet1
    5. n = f.Name
    6.  
    7. For i = 2 To s.UsedRange.Rows.Count
    8.     event1 = f.Cells(6, 2)
    9. If s.Cells(i, 3) = f.Cells(3, 2) And s.Cells(i, 4) = f.Cells(4, 2) And s.Cells(i, 5) = f.Cells(6, 2) Then
    10. If event1 = "100m" Or event1 = "200m" Or event1 = "300m" Or event1 = "400m" Or event1 = "800m" Or event1 = "1500m" Or event1 = "Relay" Then
    11. If f.Cells(8, 2) < s.Cells(i, 6) Then
    12. s.Cells(i, 2) = f.Cells(2, 2)      
    13.             s.Cells(i, 6) = f.Cells(8, 2)
    14.             s.Cells(i, 7) = Year(Now)
    15. MsgBox "Record Broken!", vbInformation, "Record Broken"
    16.  
    17. Else
    18. If f.Cells(8, 2) > s.Cells(i, 6) Then
    19. s.Cells(i, 2) = f.Cells(2, 2)      
    20.             s.Cells(i, 6) = f.Cells(8, 2)
    21.             s.Cells(i, 7) = Year(Now)
    22. MsgBox "Record Broken!", vbInformation, "Record Broken"
    23. End If
    24.            
    25.         End If
    26.         End If
    27.         Exit For
    28.     End If
    29. Next
    30. End Sub
    Last edited by asgsoft; Jul 9th, 2006 at 12:51 PM.

  14. #14
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Updating records

    what error, where?

    try using select case or your events, it will probably be much easier to do that way

    pete

  15. #15

    Thread Starter
    Addicted Member
    Join Date
    Feb 2005
    Posts
    163

    Re: Updating records

    I changed it a bit and I am not able to see if the sport is a distance one. I am not getting any errors but it won't just recognise them. Have a look at this please:

    VB Code:
    1. Sub checkrecord2()
    2. Dim s As Sheet4, f As Sheet1
    3. Set s = Sheet4
    4. Set f = Sheet1
    5. n = f.Name
    6. 's.Activate
    7. For i = 2 To s.UsedRange.Rows.Count
    8.     event1 = f.Cells(6, 2)
    9. If s.Cells(i, 3) = f.Cells(3, 2) And s.Cells(i, 4) = f.Cells(4, 2) And s.Cells(i, 5) = f.Cells(6, 2) Then
    10. If event1 = "100m" Or event1 = "200m" Or event1 = "300m" Or event1 = "400m" Or event1 = "800m" Or event1 = "1500m" Or event1 = "Relay" Then
    11. If f.Cells(8, 2) < s.Cells(i, 6) Then
    12. s.Cells(i, 2) = f.Cells(2, 2)      ' update record if better
    13.             s.Cells(i, 6) = f.Cells(8, 2)
    14.             s.Cells(i, 7) = Year(Now)
    15. MsgBox "Record Broken!", vbInformation, "Record Broken"
    16.  
    17. End If
    18. If event1 = "Shot Putt" Or event1 = "Discus" Or event1 = "Javelin" Or event1 = "High Jump" Or event1 = "Long Jump" Or event1 = "Triple Jump" Then
    19.  
    20. If f.Cells(8, 2) > s.Cells(i, 6) Then
    21. s.Cells(i, 2) = f.Cells(2, 2)      ' update record if better
    22.             s.Cells(i, 6) = f.Cells(8, 2)
    23.             s.Cells(i, 7) = Year(Now)
    24. MsgBox "Record Broken!", vbInformation, "Record Broken"
    25. End If
    26.            
    27.         End If
    28.         End If
    29.         Exit For
    30.     End If
    31. Next
    32. 'for i = 1 to
    33.  
    34.  
    35.  
    36. End Sub

  16. #16
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Updating records

    VB Code:
    1. Sub checkrecord()
    2. Dim s As Sheet4, f As Sheet1, newrecord As Boolean
    3. Set s = Sheet4
    4. Set f = Sheet1
    5. n = f.Name
    6. 's.Activate
    7. For i = 2 To s.UsedRange.Rows.Count
    8.     If s.Cells(i, 3) = f.Cells(3, 2) And s.Cells(i, 4) = f.Cells(4, 2) And s.Cells(i, 5) = f.Cells(6, 2) Then
    9.         a = f.Cells(6, 2)
    10.         Select Case f.Cells(6, 2)
    11.             Case "100m", "200m", "400m", "800m", "1500m", "Relay"
    12.                 If f.Cells(8, 2) < s.Cells(i, 6) Then newrecord = True
    13.             Case "Shot Putt", "Long Jump", "Triple Jump", "High Jump", "Discus", "Javelin"
    14.                 If f.Cells(8, 2) > s.Cells(i, 6) Then newrecord = True
    15.             Case Else
    16.                 MsgBox "This event not in record list"
    17.         End Select
    18.        
    19.        
    20.        
    21.         If newrecord Then 'compare time/distance, not sure if high or low is better
    22.             s.Cells(i, 2) = f.Cells(2, 2)      ' update record if better
    23.             s.Cells(i, 6) = f.Cells(8, 2)
    24.             s.Cells(i, 7) = Year(Now)
    25.            
    26.         End If
    27.         Exit For
    28.     End If
    29. Next
    30. 'for i = 1 to
    31.  
    32.  
    33.  
    34. End Sub

    try this
    pete

  17. #17

    Thread Starter
    Addicted Member
    Join Date
    Feb 2005
    Posts
    163

    Re: Updating records

    it works

    you are a genious

  18. #18
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Updating records

    Case Else
    MsgBox "This event not in record list"

    this will never do anything, because if the event does not match one of the events already in the record list it will never get that far, i think this is the case with "Shot" or one event that is different in your drop down box to what is in the records, also if you start a new event there is no provision to add that to the records, it will only update existing records

    pete

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width