Results 1 to 8 of 8
  1. #1
    Alib is offline Novice
    Windows 10 Access 2016
    Join Date
    Jan 2018
    Posts
    5

    Recordset

    I’m trying to test whether a record exists before entering a new record


    I have a recordset that returns a record with 1 field with a value of 0. This isn’t a valid answer to the query so not sure what it is? It does mean I can’t test for .eof and .bof
    What would cause this and how can I cater for it?

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    what do you want to see? If the record exists, there will be a key. (autoID) Are you using them here?
    otherwise ask for the field you DO want with some value. No BOF nor EOF needed.
    Dlookup is always a good check too.

  3. #3
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    or use dcount, but if using recordsets, if no records are returned then bof and eof will both be true
    Suggest provide your code so we can see what you are trying to do

  4. #4
    Alib is offline Novice
    Windows 10 Access 2016
    Join Date
    Jan 2018
    Posts
    5
    I think my problem is with the date:

    The record that exists is for the date 2nd March 2018 - stored in the TrainingRecords_t table as 02/03/2018

    There isn't a TraineeID = 0 but when a record ISN'T found it still returns 1 record with a 0 in the TraineeID field

    strCheck returns the date as 03/02/2018

    My table is: see image

    Click image for larger version. 

Name:	TableDesign.PNG 
Views:	29 
Size:	10.2 KB 
ID:	32432
    Course

    Here is the code snippet that generates the SQL string for the recordset

    dteDate = Format(dtpDate, "dd/mm/yyyy")
    'if codes has got to here then ther are no errors
    'open a connection and check it is not a duplicate record
    'generate select query based on new record being added
    strCheck = ""
    strCheck = "SELECT TrainingRecords_t.TraineeID "
    strCheck = strCheck & "FROM TrainingRecords_t "
    strCheck = strCheck & "WHERE TrainingRecords_t.TraineeID= " & cbxTrainee & " AND TrainingRecords_t.CourseDate=#" & dteDate & "# AND TrainingRecords_t.CourseID= " & cbxCourseTitle

  5. #5
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    when using dates in sql you need to use the US date format of month/day/year, so

    dteDate = Format(dtpDate, "dd/mm/yyyy")

    should be

    dteDate = Format(dtpDate, "mm/dd/yyyy")

  6. #6
    Alib is offline Novice
    Windows 10 Access 2016
    Join Date
    Jan 2018
    Posts
    5
    Thank you Ajax. That seems to solved my issue.

  7. #7
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    RE: your table "TrainingRecords_T" design.

    Having a multi-field PK field is the wrong way to go. You should have the autonumber field "TrainingRecordID" as the PK field and "TraineeID", "CourseID" and "CourseDate" as a secondary index to prevent duplicates.
    See Microsoft Access Tables: Primary Key Tips and Techniques
    Read this several times (I still go back and read it -must be up to 100 times by now). Pay special attention to the last 2 headings.


    And Welcome to the forum...

  8. #8
    Alib is offline Novice
    Windows 10 Access 2016
    Join Date
    Jan 2018
    Posts
    5
    Thank you. Table designs duly changed

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

Similar Threads

  1. Replies: 4
    Last Post: 01-22-2015, 09:57 AM
  2. Replies: 6
    Last Post: 12-03-2013, 11:14 PM
  3. How to Select second Recordset from first recordset
    By FrustratedAlso in forum Programming
    Replies: 28
    Last Post: 05-10-2012, 05:45 PM
  4. Replies: 2
    Last Post: 03-08-2012, 12:59 PM
  5. Replies: 1
    Last Post: 11-13-2009, 03:03 AM

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