Results 1 to 5 of 5
  1. #1
    Khalil Handal is offline Competent Performer
    Windows 10 Access 2010 32bit
    Join Date
    Jun 2016
    Posts
    310

    Criteria to check for existing set of records


    Hi to all,I have a Database with a query linked to an Excel wroksheet. The worksheet shows monthly payments. The values are different each month.When I open the database, the query shows the values of that specific month. I was able to add the values from the query to a table; this table is used as a history table for all months. One of the fields is the month name and is shown as MMM YYYY (example: Feb 2025 Type in the Excel sheet).I want to be able to check for the month before adding records to the history table named tblHistoryPayments. Example: If (Feb 2025 ) exists then a message box will appear saying that payment for this month is already added to the table. I have a command button to add the records to the table tblhistoryPayments.How can I do this and add the criteria?Sincerely,Khalil

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,574
    Use DCount()
    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

  3. #3
    Khalil Handal is offline Competent Performer
    Windows 10 Access 2010 32bit
    Join Date
    Jun 2016
    Posts
    310
    Hi,

    I tried the following:
    Code:
    CountRec = DCount("[pkHistoryPayroll]", "tblHistory", "[F17]=" & Me.txtLastMonth)
    F17 is the field containing the value of months.
    but have the error:
    3075 runtime error missing operator in query expression '[F17]=Mar 2025'
    any ideas?

    Khalil

  4. #4
    Join Date
    Apr 2017
    Posts
    1,793
    The value of Me.txtLastMonth is a string, so probably something like
    Code:
    CountRec = DCount("[pkHistoryPayroll]", "tblHistory", "[F17]='" & Me.txtLastMonth & "'")
    I myself prefer to use month numbers like 202503 (a numeric value). In case you need for some reason the text value, like you used, simply add a months table like tblMonths: MonthNo, MonthTxt, and read the matching text from there. Or tblMonths: MonthNo, TxtType, MonthTxt - which allows to have text values of months defined for various text types like formats, or languages, or whatever.

  5. #5
    Khalil Handal is offline Competent Performer
    Windows 10 Access 2010 32bit
    Join Date
    Jun 2016
    Posts
    310
    Hi,
    Thank you very much
    Khalil

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

Similar Threads

  1. Replies: 1
    Last Post: 08-17-2020, 10:10 AM
  2. Replies: 5
    Last Post: 09-14-2018, 06:08 AM
  3. Replies: 19
    Last Post: 02-14-2015, 11:44 AM
  4. Set db set Set rst - what does it mean?
    By gg80 in forum Programming
    Replies: 4
    Last Post: 11-07-2013, 03:20 PM
  5. check existing records
    By zul in forum Programming
    Replies: 2
    Last Post: 08-24-2011, 03:41 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