473,395 Members | 2,010 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Number not incrementing using a Recordset method

547 512MB
I have been struggling for 2 weeks now with an incrementing problem.
If you add a raceNo once then the lapno =1. If same number is added again, then the lapno should be 2 etc etc
I use A2007 but attachment is saved as A2003.
I would prefer to filter the strwhere in code on "RaceName" and "RaceNo" and exclude dates if possible.
I have attached part of the application with the tables/forms i use, if anybody can assist please?
I have an idea that the problem has to do with
Expand|Select|Wrap|Line Numbers
  1. strWhere = "[RaceDate] = #" & [Forms]![FrmRTmainChip]![RacingDate] & "# AND [RaceNo] = " & _
  2.             varRet(0)
Expand|Select|Wrap|Line Numbers
  1. Dim varRet As Variant
  2. Dim MyDB As DAO.Database
  3. 'Dim rst As DAO.Recordset
  4. Dim rst2 As DAO.Recordset
  5. Dim strInputString As String
  6. Dim strWhere As String
  7. Dim intLapNum As Integer
  8.  
  9. If IsNull(Me![strinput1]) Then Exit Sub
  10.  
  11. Set MyDB = CurrentDb
  12. Set rst2 = MyDB.OpenRecordset("RaceEntry2", dbOpenDynaset, dbAppendOnly)
  13.  
  14. strInputString = Me![strinput1]
  15.  
  16.  'See if Trailing Comma (,) is present, if so Extract it!
  17. If Right$(strInputString, 1) = "," Then
  18.    strInputString = Left$(strInputString, Len(strInputString) - 1)
  19. End If
  20.  
  21. varRet = Split(strInputString, ",")
  22.  
  23. 'Let's find the Lap Number based on the Race Date, Race Name, and Race Number   -  THE RACENAME HAS A PROBLEM  _ TEMPORARILY REMOVED
  24. 'strWhere = "[RaceDate] = #" & [Forms]![FrmRTmainChip]![RacingDate] & "# AND " & _
  25.            "[RaceName] = '" & Forms![FrmRTmainChip]![RaceName] & "' AND [RaceNumber] = " & _
  26.             varRet(0)
  27. strWhere = "[RaceDate] = #" & [Forms]![FrmRTmainChip]![RacingDate] & "# AND [RaceNo] = " & _
  28.             varRet(0)
  29. intLapNum = Nz(DMax("[LapNo]", "RaceEntry2", strWhere), 0)
  30.  
  31. 'Select Case UBound(varRet)      'How many Race Numbers?
  32.   'Case 0        '1 Race#
  33.  
  34. With rst2
  35.       .AddNew
  36.    ![RaceName] = Forms![FrmRTmainChip]![RaceName]  
  37.         ![RaceNo] = varRet(0)
  38.         ![FinishTime] = Format(Now(), "General Date")
  39.         ![RaceDate] = [Forms]![FrmRTmainChip]![RacingDate]
  40.         ![Lapno] = IIf(intLapNum = 0, 1, intLapNum + 1)
  41.         .Fields("Lap" & CStr(intLapNum + 1)) = Format(Now(), "General Date")
  42.  
  43.       .Update
  44.     End With
  45.   rst2.Close
  46.  Set rst2 = Nothing
  47.  
  48. Me.strinput1.Value = ""
  49.  
  50. 'Me.Requery
  51.  
  52. [Forms]![FrmRTmainChip]![RaceEntry2sf].Requery
  53.  
  54. With Me
  55.   ![text1].SetFocus        'Can use any Control
  56.   ![strinput1].SetFocus
  57. End With
Nov 9 '12 #1
7 1790
neelsfer
547 512MB
I have just cleaned up the code a bit and rather use the new attachment below please
RaceName = textfieldtype ; Racenumber =number ; RaceDate =long date; LapNo=number type
Expand|Select|Wrap|Line Numbers
  1. Dim varRet As Variant
  2. Dim MyDB As DAO.Database
  3. Dim rst2 As DAO.Recordset
  4.  
  5. Dim strWhere As String
  6. Dim intLapNum As Integer
  7.  
  8. If IsNull(Me![strInput1]) Then Exit Sub
  9.  
  10. Set MyDB = CurrentDb
  11. Set rst2 = MyDB.OpenRecordset("RaceEntry2", dbOpenDynaset, dbAppendOnly)
  12.  
  13.  
  14. 'Let's find the Lap Number based on the Race Date, Race Name, and Race Number
  15. 'strWhere = "[RaceDate] = #" & [Forms]![frmXCTiming]![RacingDate] & "# AND " & _
  16.            "[RaceName] = '" & Forms![frmXCTiming]![RaceName] & "' AND [RaceNumber] = " & _
  17.             varRet(0) -     THE RACENAME HAS A PROBLEM  _ TEMPORARILY REMOVED
  18. strWhere = "[RaceDate] = #" & [Forms]![frmXCTiming]![Racedate] & "# AND [RaceNo] = " & _
  19.             Me.strInput1
  20. intLapNum = Nz(DMax("[LapNo]", "RaceEntry2", strWhere), 0)
  21.  
  22.  
  23. With rst2
  24.       .AddNew
  25.  ![RaceName] = Forms![frmXCTiming]![RaceName]
  26.         ![RaceNo] = Me.strInput1
  27.         ![FinishTime] = Format(Now(), "General Date")
  28.         ![Racedate] = [Forms]![frmXCTiming]![Racedate]
  29.         ![Lapno] = IIf(intLapNum = 0, 1, intLapNum + 1)
  30.         .Fields("Lap" & CStr(intLapNum + 1)) = Format(Now(), "General Date")
  31.  
  32.       .Update
  33.     End With
  34.   rst2.Close
  35.  Set rst2 = Nothing
  36.  
  37. Me.strInput1.Value = ""
  38.  
  39. 'Me.Requery
  40.  
  41. [Forms]![frmXCTiming]![RaceEntry2SF].Requery
  42.  
  43. With Me
  44.   ![Text1].SetFocus        'Can use any Control
  45.   ![strInput1].SetFocus
  46. End With
Attached Files
File Type: zip RacetimeTest2003.zip (34.6 KB, 80 views)
Nov 10 '12 #2
zmbd
5,501 Expert Mod 4TB
Ok,
I haven't opened your attachment... but I have a question... is the "RaceNo" always a unique value or is it only unique within a given date and racename?

Basic trouble shooting:
As given in your second post:
As you don't give any details as to what is actually happening, errors, etc..., I can only guess that you are getting the new record entry that lines 23-33 are calling for and that the value in [Lap] is only returning a value of 1 and the remaining field values are correct.

Working on that assumption:
Let check how your conditional is resolving and if you
actually have any returned information in your dmax on line 20
as listed in your Second posted code:
At Line 21 or 22; enter STOP compile and save
Run your application entering the racenumber or whatever it is that you need to get the application to this point.
Upon entering break mode and the VBA editor showing
<ctrl+g>
in immediate window
?strwhere
?intLapNum
Check these results against what you're expecting.
Please post back the result for the strwhere.
Nov 10 '12 #3
neelsfer
547 512MB
It does not increment the lapno field when a RaceNo is added.
Every RaceNo is unique to one person for that race. If a race consists of ie 5 laps that a RaceNo and finishtime will be added to the DB untill the 5 laps are completed.
I think my problem is with line 8+9
Nov 10 '12 #4
zmbd
5,501 Expert Mod 4TB
8 and 9 maybe; however, you only increase my suspicion that you have a malformed string.

Do as you want; however, it would be helpful to have the information I asked for....
Nov 10 '12 #5
neelsfer
547 512MB
Zmbd, a friend came to my rescue yesterday and in between a kids party at home we fixed it last night (South Africa time).
The VBA producing my required results for anybody interested,looks like this. I removed the strwhere
Expand|Select|Wrap|Line Numbers
  1. Dim varRet As Variant
  2. Dim MyDB As DAO.Database
  3. Dim rst2 As DAO.Recordset
  4. Dim intLapNum As Integer
  5. If IsNull(Me![strInput1]) Then Exit Sub
  6. Set MyDB = CurrentDb
  7. Set rst2 = MyDB.OpenRecordset("RaceEntry2", dbOpenDynaset, dbAppendOnly)
  8. intLapNum = Nz(DMax("[LapNo]", "RaceEntry2", "[RaceNo] = " & Me![strInput1] & _
  9. " AND [RaceName] = '" & [Forms]![frmxctiming]![RaceName] & "'"), 0)
  10. With rst2
  11.       .AddNew
  12.         ![RaceName] = Forms![frmxctiming]![RaceName]
  13.         ![RaceNo] = Me.strInput1
  14.         ![finishtime] = Format(Now(), "General Date")
  15.         ![Racedate] = [Forms]![frmxctiming]![Racedate]
  16.         ![Lapno] = IIf(intLapNum = 0, 1, intLapNum + 1)
  17.         .Fields("Lap" & CStr(intLapNum + 1)) = Format(Now(), "General Date")
  18.  
  19.       .update
  20.       End With
  21.       rst2.close
  22.       Set rst2 = Nothing
  23.  
  24.       Me.strInput1.Value = ""
  25.  
  26. 'Me.Requery
  27.  
  28. [Forms]![frmxctiming]![RaceEntry2SF].Requery
  29.  
  30. With Me
  31.   ![Text1].SetFocus        'Can use any Control
  32.   ![strInput1].SetFocus
  33. End With
Nov 11 '12 #6
zmbd
5,501 Expert Mod 4TB
Which for me adds a lot of weight to the malformed string hypothesis, which you might have confirmed using the method I offered and the information it would have returned.
Nov 11 '12 #7
NeoPa
32,556 Expert Mod 16PB
Neels, Please see my PM.
Nov 11 '12 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Keith | last post by:
Is there a way to publish only one file in VS.NET 2003 using FPSE method? In FP client I can select one file at a time to publish. My web is large and it takes too long to publish the whole...
4
by: Velhari | last post by:
Hi all, We all know in GET method upto 2048 characters can be appended into URL. In the Same way what is the limit of sending data to server by using POST Method. Why asking this question...
2
by: =?Utf-8?B?am9obmFicmFoYW0xMDE=?= | last post by:
hello, I'm trying to write a some text to a text file using WriteAllText method. This method works fine but I don't understand how can I use format specifiers to format the text as we use in C i.e...
1
by: jackiepajo | last post by:
I want to delete a picture that i uploaded but icannot delete... by the way im using recordset but i do not how it really works... i just want to have some delete functio... please help..
0
by: 2pt2mill | last post by:
I have been using SharpZipLib for over a year with no problems, but it doesn't support files zipped using compression method 6 (Imploding). This seems to be an older method of compression utilized...
1
by: munusoni | last post by:
Hi everyone, i am using ASP 3.0 to create web pages for a college project and i am having problems in using recordset object through session object to pass data to all web pages.Anyone tell me how...
5
by: JohnDriver | last post by:
Hi, I am having a form which has a text box and 3 radio buttons. I am using GET method in Ajax to pass the value. I can pass the value of the textbox fine but how to pass the value of radio...
0
by: DKn | last post by:
Hi, I am doing shutdown for a remote system using this method InvokeMethod("Win32Shutdown", inParams, null); in C#.Net 2.0. Once the shutdown is done, how to get the status , whether the...
0
by: Neelesh2007 | last post by:
Hi all, I have project with VB6.0 and Access-2003. I have datagrid and ADODC as datasource to retrieve records from database. To export the data of datagrid to Excel I am using Copy From Recordset...
2
by: Rakulkumar | last post by:
how can i print the pdf file using binarywrite method in asp.i can print the text file using Response.binarywrite method but i cnat print the pdf files
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.