Page 1 of 2 12 LastLast
Results 1 to 15 of 19
  1. #1
    Harold7 is offline Novice
    Windows 11 Office 365
    Join Date
    Aug 2023
    Posts
    9

    I need to check a table to see if the record is there using two columns


    I need to check the below table to see if the record is there using VBA when I click the button. Then run an append query if the record doesn't exist, and run an update query if the record there. Please note that I should only add a new record if both the EmployeeID and AttendanceDate do not exist.

    The code that I have tried so far is this:

    Code:
    If DLookup("EmployeeID", "AttendanceTable", "EmployeeID= '" & txtEmployeeID & "'") > 0 Then
    
    ' Run update query
    
    Else
    
    ' Run append query
    
    End If



    AttendanceTable

    AttendanceID AttendanceDate EmployeeID EmployeeName AttendanceCode
    000001 08/08/2023 101 Adam P
    000002 08/08/2023 102 Sam P
    000003 08/08/2023 103 John P

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    At the bottom is an example of multiple criteria:

    http://theaccessweb.com/general/gen0018.htm
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    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.

  4. #4
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    @June7 - are you sure that's the right link? The first post seems to indicate the thread is 12 years old.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  5. #5
    Harold7 is offline Novice
    Windows 11 Office 365
    Join Date
    Aug 2023
    Posts
    9
    Quote Originally Posted by pbaldy View Post
    At the bottom is an example of multiple criteria:

    http://theaccessweb.com/general/gen0018.htm
    Thank you, that was very helpful.

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Happy to help!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Link opens correct for me. Question asked 23 hours ago.
    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.

  8. #8
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Quote Originally Posted by Micron View Post
    @June7 - are you sure that's the right link? The first post seems to indicate the thread is 12 years old.
    Works for me, but shouldn't DCount() be used if comparing to > 0 ?
    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

  9. #9
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Quote Originally Posted by Welshgasman View Post
    Works for me, but shouldn't DCount() be used if comparing to > 0 ?
    That was noted in comment below StackOverflow question.
    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.

  10. #10
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    Then there must be something wrong with what the site shows or "Asked 12 years, 2 months ago" doesn't mean what I think it does.
    Click image for larger version. 

Name:	1StackO.jpg 
Views:	10 
Size:	25.1 KB 
ID:	50640
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  11. #11
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Micron, don't know why you are opening that question. That is the question that was flagged as an old question with answer relevant to new question. The link I posted is to the new question.
    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.

  12. #12
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    FYI if I click on your crosspost link I also go to the 12-year-old question that Micron gets.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  13. #13
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    Micron, don't know why you are opening that question
    Because that's where your link takes me. Never mind, not real important.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  14. #14
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Hmm, on my phone with chrome it takes me to the 13 year old thread? On my laptop it is fine?
    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

  15. #15
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    I wonder if people who are registered and logged in at SO get a different result? I'm not a user there.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 7
    Last Post: 07-21-2023, 10:27 AM
  2. dlookup to check record in another table
    By muk5063 in forum Access
    Replies: 4
    Last Post: 12-27-2015, 01:27 PM
  3. Replies: 1
    Last Post: 08-09-2015, 10:03 AM
  4. Check if record is exits in table
    By adam23262 in forum Access
    Replies: 4
    Last Post: 02-08-2013, 01:00 PM
  5. Replies: 1
    Last Post: 03-06-2012, 06:45 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