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

    DAO query searching for today's date from a table.

    Hi. It's been years since I've used access and I've only ever been a beginner.

    I'm an English as a second language teacher writing a database to check and give practice for taught English expressions. Students basically listen to the sentences, then choose the words of the sentence from the numerous combo boxes populated with their words. The database has a "word" table containing all the words to choose from, a "sentence" table containing all their sentences and a "studentrecords" table which adds a record for each day - date, correct answers, wrong answers, candy given (they get candy for motivation), a check box for starting a new day (so they can't do a sentence more than once a day).

    I'm having trouble searching for that date in the student records field. When they open the app, it needs to check for whether they've already done some that day or not, and whether they've pressed the "Prepare" button to move their sentences to the new day. I know this sounds strange, but I want the sentences to be slowly spaced between views but not specific to date, so that students can use the app any number of times a week, but not see a sentence twice on one day. So I have a field that increases (number of times before viewing again) by one every press of this button.

    So I need the formload to check if a record for that date exists or not, and if it does exist, check whether that NewPrepare checkbox field has been triggered or not. The problem is that even though there is definitely a record in the StudentRecords with a ScoreDate for today, it's just not finding it - I continually get a RecordCount = 0. I vaguely remember something about different date formats, but couldn't even find a tutorial on how to search records with various dates. Please also see attachments below as pictures of the relevant information. Here is my query (note that I tried two ways to find the date) - this is a small part of the "form_load" of the Student Form:

    Thanks in advance.

    Dim Dailyrst As DAO.Recordset
    Dim Dailydb As DAO.Database

    Set Dailydb = CurrentDb
    ' Set Dailyrst = CurrentDb.OpenRecordset("select * from StudentRecords where ScoreDate = #" & Date & "#")
    Set Dailyrst = CurrentDb.OpenRecordset("select * from StudentRecords where ScoreDate = " & Date & "")

    'Set Prepare button: if a record exists for today where NewPrepare has been triggered, then disable the Prepare button


    If Dailyrst.RecordCount = 1 Then
    If Dailyrst!NewPrepare = True Then
    Me.BtnPlay.SetFocus
    Me.BtnNewDay.Enabled = False
    End If
    End If

    'If there is no record created for today, then create a new one.
    If Dailyrst.RecordCount = 0 Then
    Dailyrst.AddNew

    Dailyrst!ScoreDate = Date
    Dailyrst!CorrectAnswers = 0
    Dailyrst!WrongAnswers = 0
    Dailyrst!candyGiven = 0
    Dailyrst!NewPrepare = False
    Me.BtnNewDay.Enabled = True
    Me.BtnNewDay.SetFocus

    Dailyrst.Update
    End If


    Dailyrst.Close
    Set Dailyrst = Nothing
    Set Dailydb = Nothing

    Click image for larger version. 

Name:	Student Form.jpg 
Views:	16 
Size:	203.6 KB 
ID:	51420Click image for larger version. 

Name:	StudentRecordsData.jpg 
Views:	16 
Size:	117.7 KB 
ID:	51421Click image for larger version. 

Name:	StudentRecordsDesignDate.jpg 
Views:	15 
Size:	176.0 KB 
ID:	51423
    Attached Thumbnails Attached Thumbnails StudentRecordsDesign.jpg  

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2019
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    Perhaps you need () after Date:
    Code:
    CurrentDb.OpenRecordset("select * from StudentRecords where ScoreDate = #" & Date() & "#")
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    Try

    where ScoreDate = Date()")

  4. #4
    Frannilea is offline Novice
    Windows 10 Access 2007
    Join Date
    Jul 2020
    Posts
    27
    Thank you! That worked!!

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

Similar Threads

  1. Replies: 3
    Last Post: 06-18-2019, 04:01 PM
  2. Replies: 4
    Last Post: 01-20-2015, 08:26 AM
  3. Replies: 5
    Last Post: 10-12-2012, 11:00 AM
  4. Replies: 7
    Last Post: 07-12-2012, 02:35 PM
  5. query date that is five years older than today
    By cpsummer in forum Queries
    Replies: 2
    Last Post: 09-26-2007, 02:31 PM

Tags for this Thread

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