Results 1 to 8 of 8
  1. #1
    Frannilea is offline Novice
    Windows 10 Access 2007
    Join Date
    Jul 2020
    Posts
    27

    DAO query with very weird results

    Hi. Here I am again. I'm a teacher (definitely a noob coder!) building an English as a second language app where my students listen to the English sentence, then choose the correct words from the combo boxes and translation from the listbox, the app checks if they are correct, then gives them points for candy. I have a simple space-repetition counter, "LevelCounter" that adds a point level every time they get the sentence correct (I'm not using specific dates because this is more flexible - they can then use it daily or weekly and it's simply spaced on use). So every sentences starts on "0", then if they get it correct, moves up a level to "1" (so they get it next use), then if they get it correct it moves to "2" (so they get it in two uses time), then 3, then 4, and so on. If they get the sentence wrong, it moves down a sentence level. On saving each sentence, that new level is copied across to a TimesUntilNextUseCounter, which counts down 1 every time the NewDay button is pressed. They don't get that sentence again until that counter hits zero. Thus the sentences are (hopefully) slowly spaced wider between views.

    In order to make them independent, so that I don't have to manually move that TimesUntilNewUseCounter down a number each use, I've simply given them a button on the form, which only allows them to press it once a day (using a check box on their daily records table), that basically decreases every sentence by 1 where TimesUntilUseCounter is > 0.

    But I'm getting a weird result from my table on my query. There should be 12 results but my query seems to only be retrieving one result (on the picture of the Sentences Table I've highlighted the record it finds), and that result has a TimesUntilUseCounter of 0, and thus shouldn't even be there in the results. I've wracked my brain, but it seems nonsensical to me. I've attached some pictures of the appropriate part of the data table, and the result from stepping through the code where you can see that I only get one record. What the heck am I doing wrong?? And here is my sub:

    Thank you in advance. :-)Click image for larger version. 

Name:	ChangeDayProblem.jpg 
Views:	25 
Size:	138.4 KB 
ID:	51425Click image for larger version. 

Name:	ChangeDayDataSample.jpg 
Views:	24 
Size:	178.0 KB 
ID:	51426Click image for larger version. 

Name:	StudentRecord.jpg 
Views:	24 
Size:	115.6 KB 
ID:	51427

    Private Sub BtnNewDay_Click()
    Dim PrepDaterst As DAO.Recordset 'student records
    Dim PrepDatedb As DAO.Database
    Dim Chrst As DAO.Recordset 'sentences
    Dim Chdb As DAO.Database
    Dim iCount As Integer

    Set PrepDatedb = CurrentDb
    Set PrepDaterst = CurrentDb.OpenRecordset("select * from StudentRecords where ScoreDate = Date()")

    'Only allow user to press this button once a day.
    If PrepDaterst.RecordCount <> 0 Then
    If PrepDaterst!NewPrepare = True Then
    MsgBox ("1 time only!")
    Me.BtnPlay.SetFocus
    Me.BtnNewDay.Enabled = False
    Exit Sub
    End If

    'If this is the first press this day, then find all released sentences that have not been seen today, have a TimesUntilNextUseCounter of more than zero, and subtract 1.
    If PrepDaterst!NewPrepare = False Then
    Set Chdb = CurrentDb
    'Set Chrst = CurrentDb.OpenRecordset("select [Sentences.Released],[Sentences.TimesUntilNextUseCounter],[Sentences.LastAttemptDate] from Sentences where TimesUntilNextUseCounter > 0")
    Set Chrst = CurrentDb.OpenRecordset("select * from Sentences where TimesUntilNextUseCounter > 0")

    If Chrst.RecordCount <> 0 Then
    iCount = 0
    'Set Chrst = Me.RecordsetClone
    Chrst.MoveLast
    Chrst.MoveFirst


    Do While Not Chrst.EOF
    iCount = iCount + 1
    Chrst.Edit
    If Chrst!Sentences!Released = True And Chrst!Sentences!LastAttemptDate <> Date And Chrst!Sentences!TimesUntilNextUseCounter > 0 Then
    Chrst!TimesUntilNextUseCounter = Chrst!TimesUntilNextUseCounter - 1
    End If
    Chrst.Update
    Chrst.MoveNext
    Loop
    Me.BtnNewDay.Enabled = False
    PrepDaterst!NewPrepare = True
    PrepDaterst.Update
    Chrst.Close
    Set Chrst = Nothing
    Set Chdb = Nothing
    End If
    End If
    End If


    PrepDaterst.Close


    Set PrepDaterst = Nothing
    Set PrepDatedb = Nothing



    End Sub
    Last edited by Frannilea; 02-04-2024 at 04:33 AM.

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Do MoveLast and MoveFirst before trying to get RecordCount. Review http://allenbrowne.com/ser-29.html#R...thout_MoveLast

    Where's the query output showing only this one record?

    Why are you prefixing table name to recordset fields?

    Chrst!Sentences!Released

    should probably just be

    Chrst!Released

    Please post code between CODE tags to retain indentation and readability.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Frannilea is offline Novice
    Windows 10 Access 2007
    Join Date
    Jul 2020
    Posts
    27
    Thank you so much! It worked! :-)

    I didn't think I needed the table name in the Chrst!, but I was trying all sorts of things desperately trying to make it work. I changed that back - thanks :-)

    Also, I couldn't work out how to make the controls on this website work. I press the "switch editor to source code mode" button, paste my code, and the code indents like it should, but when I save the post, it reverts back to no indent. What am I doing wrong?

    Dim PrepDaterst As DAO.Recordset 'student records
    Dim PrepDatedb As DAO.Database
    Dim Changerst As DAO.Recordset 'sentences
    Dim Changedb As DAO.Database
    Dim iCount As Integer

    Set PrepDatedb = CurrentDb
    Set PrepDaterst = CurrentDb.OpenRecordset("select * from StudentRecords where ScoreDate = Date()")

    'Only allow user to press this button once a day.
    If PrepDaterst.RecordCount <> 0 Then
    If PrepDaterst!NewPrepare = True Then
    MsgBox ("1 time only!")
    Me.BtnPlay.SetFocus
    Me.BtnNewDay.Enabled = False
    Exit Sub
    End If

    'If this is the first press this day, then find all released sentences that have not been seen today, have a TimesUntilNextUseCounter of more than zero, and subtract 1.
    If PrepDaterst!NewPrepare = False Then
    Set Changedb = CurrentDb
    'Set Changerst = CurrentDb.OpenRecordset("select [Sentences.Released],[Sentences.TimesUntilNextUseCounter],[Sentences.LastAttemptDate] from Sentences where TimesUntilNextUseCounter > 0")
    Set Changerst = CurrentDb.OpenRecordset("select * from Sentences where Sentences.TimesUntilNextUseCounter > 0")

    Changerst.MoveLast
    Changerst.MoveFirst
    If Changerst.RecordCount <> 0 Then
    iCount = 0
    'Set Changerst = Me.RecordsetClone
    Changerst.MoveLast
    Changerst.MoveFirst


    Do While Not Changerst.EOF
    iCount = iCount + 1
    Changerst.Edit
    If Changerst!Released = True And Changerst!LastAttemptDate <> Date And Changerst!TimesUntilNextUseCounter > 0 Then
    Changerst!TimesUntilNextUseCounter = Changerst!TimesUntilNextUseCounter - 1
    End If
    Changerst.Update
    Changerst.MoveNext
    Loop
    Me.BtnCandy.SetFocus
    Me.BtnNewDay.Enabled = False
    PrepDaterst.Edit
    PrepDaterst!NewPrepare = True
    PrepDaterst.Update
    Changerst.Close
    Set Changerst = Nothing
    Set Changedb = Nothing
    End If
    End If
    End If


    PrepDaterst.Close
    Set PrepDaterst = Nothing
    Set PrepDatedb = Nothing

  4. #4
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    What am I doing wrong?
    copy/paste your indented code, highlight it and click the # button

  5. #5
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Or click the # button then paste between CODE tags.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    Or click the # button first. Then your cursor should be located between the tags. Then paste. That way you don't have to paste then select/highlight it all just to enclose it in the tags. So I just copy, click # then ctrl+v and done. At least that's how it works for me with my browser.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  7. #7
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    I tend to just key in [ c o d e ], paste, then [ / c o d e ]

    Note, without the spaces, else it would act on the tags as a code block.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  8. #8
    Frannilea is offline Novice
    Windows 10 Access 2007
    Join Date
    Jul 2020
    Posts
    27
    Thank you everyone. This has to prove I'm a noob, beyond my silly questions and probably questionable code. I try again next time.

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

Similar Threads

  1. Weird Crosstab results
    By SteveApa in forum Queries
    Replies: 2
    Last Post: 01-28-2015, 07:04 AM
  2. Weird Query Results using Percentage criterion
    By david.semadeni in forum Queries
    Replies: 6
    Last Post: 04-09-2012, 10:59 AM
  3. Replies: 2
    Last Post: 03-27-2012, 01:59 AM
  4. Weird Query results
    By UCBFireCenter in forum Queries
    Replies: 0
    Last Post: 10-06-2009, 03:38 PM
  5. Get the sum of decimal values - weird results
    By BengtCarlsson in forum Queries
    Replies: 2
    Last Post: 02-10-2006, 04:29 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