Page 1 of 2 12 LastLast
Results 1 to 15 of 24
  1. #1
    yrstruly is offline Competent Performer
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2024
    Posts
    122

    Positive Test Flagging & Reminders

    I am developing a Microsoft Access-based system to manage virus/bacterial retesting for plant blocks. The system tracks testing schedules, flags positive tests, and automates retest reminders using VBA and a subform to display test records.
    Files(upload function dont work)https://drive.google.com/file/d/1I5F...ew?usp=sharing



    ✅ What I Have Done So Far



    1️⃣ Created a Table for Retesting (TblBlockRetesting)

    Subform: QfrmBlockPath_subform - Link & Functionality

    • This subform is embedded in the Blocks Administration Form (frmBlocks Admin).
    • It is linked to the main form using:
      • Master Field: Nr
      • Child Field: Nr, Block

    Testing Reminder - How It Works

    ✅ Checks if a block has tested positive (TestResult = "A/EC").
    ✅ Looks at the TestDate column to determine if the test was 5+ years ago.
    ✅ Inserts overdue tests into TblBlockRetesting if not already recorded.
    ✅ Triggers a pop-up reminder listing overdue blocks.

    I tried this VBA code,it is currently calling a previous Macro, dont know how to get rid of it.
    Code:
    Private Sub Form_Open(Cancel As Integer)
    Code:
        Dim db As DAO.Database
        Dim rs As DAO.Recordset
        Dim sqlQuery As String
        Dim testDateThreshold As Date
        Dim blockNr As Long
        Dim virusType As String
        Dim originalTestDate As Date
        Dim retestDueDate As Date
        Dim retestExists As Variant
        Dim messageText As String
        
        ' Set the date threshold (5 years ago from today)
        testDateThreshold = DateAdd("yyyy", -5, Date)
    
    
        ' Open the current database
        Set db = CurrentDb()
    
    
        ' SQL query to find blocks that tested positive (A/EC) 5+ years ago
        sqlQuery = "SELECT Nr, Block, TestResult, TestDate FROM TblBlocks " & _
                   "WHERE TestResult='A/EC' AND TestDate <= #" & Format(testDateThreshold, "MM/DD/YYYY") & "#"
    
    
        Set rs = db.OpenRecordset(sqlQuery, dbOpenDynaset)
    
    
        ' Initialize message text
        messageText = "The following blocks require retesting:" & vbCrLf & vbCrLf
    
    
        ' Check if records exist
        If Not rs.EOF Then
            While Not rs.EOF
                blockNr = rs!Nr
                virusType = "A/EC" ' Since we are filtering for this specific test result
                originalTestDate = rs!TestDate
                retestDueDate = DateAdd("yyyy", 5, originalTestDate)
                
                ' Check if this block is already in the Retest Schedule table
                retestExists = Nz(DLookup("Nr", "TblBlockRetesting", "Nr=" & blockNr & " AND VirusType='" & virusType & "'"), 0)
    
    
                ' If the block is not already scheduled for retesting, insert it
                If retestExists = 0 Then
                    db.Execute "INSERT INTO TblBlockRetesting (Nr, BlockName, VirusType, OriginalTestDate, NextDueDate, Retest_Status) " & _
                               "VALUES (" & blockNr & ", '" & rs!Block & "', '" & virusType & "', #" & Format(originalTestDate, "MM/DD/YYYY") & "#, #" & Format(retestDueDate, "MM/DD/YYYY") & "#, 'Due');"
                End If
    
    
                ' Add block info to the message pop-up
                messageText = messageText & "Block Nr: " & blockNr & " | Block: " & rs!Block & _
                              " | Due Date: " & retestDueDate & vbCrLf
    
    
                ' Move to next record
                rs.MoveNext
            Wend
    
    
            ' Show pop-up reminder
            MsgBox messageText, vbExclamation, "Retesting Alert"
        Else
            MsgBox "No blocks require retesting.", vbInformation, "Retesting Check Complete"
        End If
    
    
        ' Close resources
        rs.Close
        Set rs = Nothing
        Set db = Nothing
    End Sub


  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 11 Access 2021
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    Where is the call to a macro?

    Why don't you attach files to post as instructed in other thread and at bottom of my post?
    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
    jojowhite's Avatar
    jojowhite is offline Competent Performer
    Windows 11 Access 2021
    Join Date
    Jan 2025
    Posts
    434

  4. #4
    yrstruly is offline Competent Performer
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2024
    Posts
    122
    I am having great difficculty uploading anything on this site. I have changed browsers and followed your steps on how to attached, nothings works. Thats why i am posting links.

    When i try to run this code below, you will see that a previous Macro 'CreateDocumentStorageTable' pops up and i just cant get rid of it.Please assist.

    Code:
    Option Compare Database
    
    Private Sub Form_Open(Cancel As Integer)
        Dim db As DAO.Database
        Dim rs As DAO.Recordset
        Dim sqlQuery As String
        Dim testDateThreshold As Date
        Dim blockNr As Long
        Dim blockName As String
        Dim virusType As String
        Dim originalTestDate As Date
        Dim retestDueDate As Date
        Dim retestExists As Variant
        Dim messageText As String
        
        ' Set the date threshold (5 years ago from today)
        testDateThreshold = DateAdd("yyyy", -5, Date)
    
    
        ' Open the current database
        Set db = CurrentDb()
    
    
        ' SQL query to find blocks that tested positive (A/EC) 5+ years ago
        sqlQuery = "SELECT Nr, Block, TestResult, TestDate FROM TblBlocks " & _
                   "WHERE TestResult='A/EC' AND TestDate <= #" & Format(testDateThreshold, "MM/DD/YYYY") & "#"
    
    
        Set rs = db.OpenRecordset(sqlQuery, dbOpenDynaset)
    
    
        ' Initialize message text
        messageText = "The following blocks require retesting:" & vbCrLf & vbCrLf
    
    
        ' Check if records exist
        If Not rs.EOF Then
            While Not rs.EOF
                blockNr = rs!Nr
                blockName = rs!Block
                virusType = "A/EC" ' We are filtering for this specific test result
                originalTestDate = rs!TestDate
                retestDueDate = DateAdd("yyyy", 5, originalTestDate)
                
                ' Check if this block is already in the Retest Schedule table
                retestExists = Nz(DLookup("Nr", "TblBlockRetesting", "Nr=" & blockNr & " AND VirusType='" & virusType & "'"), 0)
    
    
                ' If the block is not already scheduled for retesting, insert it
                If retestExists = 0 Then
                    db.Execute "INSERT INTO TblBlockRetesting (Nr, BlockName, VirusType, OriginalTestDate, NextDueDate, Retest_Status) " & _
                               "VALUES (" & blockNr & ", '" & Replace(blockName, "'", "''") & "', '" & virusType & "', #" & Format(originalTestDate, "MM/DD/YYYY") & "#, #" & Format(retestDueDate, "MM/DD/YYYY") & "#, 'Due');"
                End If
    
    
                ' Add block info to the message pop-up
                messageText = messageText & "Block Nr: " & blockNr & " | Block: " & blockName & _
                              " | Due Date: " & Format(retestDueDate, "dd-mmm-yyyy") & vbCrLf
    
    
                ' Move to next record
                rs.MoveNext
            Wend
    
    
            ' Show pop-up reminder if there are overdue tests
            MsgBox messageText, vbExclamation, "Retesting Alert"
        Else
            MsgBox "No blocks require retesting.", vbInformation, "Retesting Check Complete"
        End If
    
    
        ' Close resources
        rs.Close
        Set rs = Nothing
        Set db = Nothing
    End Sub
    Attached Thumbnails Attached Thumbnails macro.PNG  

  5. #5
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,564
    I cannot help with the macro issue, but why not test for those records already in the retest table? and exclude them.
    Then all the records in the set are to be uploaded?

    Could even do it in one query if someone was clever.
    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

  6. #6
    Micron is online now Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,424
    Has anyone tried to upload a file lately? I can report that the uploader seems to think about it (there's an arc that rotates) but that file won't upload. There is no message of any kind. The zip seems to be 42 Mb - I can't recall what the max is here. Is it 500 Kb?
    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
    6,564
    Works for me with Chrome.
    Attached Thumbnails Attached Thumbnails Screenshot 2025-02-25 121955.png  
    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
    Micron is online now Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,424
    Thanks. So the limit is 500 kb as I thought. That should explain the problem but there's no error message for FireFox - but there used to be.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  9. #9
    June7's Avatar
    June7 is offline VIP
    Windows 11 Access 2021
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    500kb file, 2mb ZIP folder.

    These two files after Compact & Repair then zipping do exceed 2mb, so would have to eliminate some objects from the FE file - there are a BUNCH of them.

    But I downloaded your files, again.

    None of those macros exist. Nor does the code you posted. Neither of the forms you indicated have Open event code.

    Getting past the login roadblocks was a pain but I did get your form to open and do not get the macro popup.
    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 online now Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,424
    Methinks the be is overly large. It contains queries, code modules and about 166 tables that seem to be about export failures, so a lot of unnecessary overhead. Then there is the data itself - 27 replication fields containing 388,540 records. The file space for that could be as much as 16 times what it could be.

    Anyway, I'm guessing that the original issue is that the posted code is in a standard module instead of the form's module.
    Normally I don't participate where there is an undeclared cross post. I don't wish to keep monitoring what's going on at the other sites.

    A treatise on cross posting for the OP to read
    Cross Posting Message
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  11. #11
    yrstruly is offline Competent Performer
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2024
    Posts
    122
    How did you approach investigating the duplicate records and the issue with my VBA code not producing any output?

  12. #12
    Micron is online now Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,424
    Quote Originally Posted by yrstruly View Post
    How did you approach investigating the duplicate records and the issue with your VBA code not producing any output?
    If that question is directed to me, I have no idea what it means.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  13. #13
    June7's Avatar
    June7 is offline VIP
    Windows 11 Access 2021
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    Did you see post 9?

    No one mentioned duplicate records. Micron said "replication fields" - maybe meaning fields with similar names that hold same kind of data. Might have been referring to the sets of fields like LRC, LRCDate, CommentLRC, NS, NSDate, CommentNS, etc. I counted about 44 sets.
    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.

  14. #14
    Micron is online now Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,424
    None of those macros exist. ( I counted something like 48 macros in the front end?)
    Nor does the code you posted. (Quite certain it is in a standard module)
    Neither of the forms you indicated have Open event code. ( agreed - at least on the one I checked)

    Getting past the login roadblocks was a pain but I did get your form to open and do not get the macro popup.
    I just closed the login form then showed the nav pane and went from there. Shouldn't have to log in to check design.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  15. #15
    Micron is online now Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,424
    fields with similar names that hold same kind of data. Might have been referring to the sets of fields like LRC, LRCDate, CommentLRC, NS, NSDate, CommentNS, etc. I counted about 44 sets.
    No, I meant they are replication id fields (GUID) which take 16 bytes of space for each record. However, checking out what you meant also led me to find at least one OLE object field. I can re-run my code to count those if anyone cares.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

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

Similar Threads

  1. Flagging Archived Data
    By kd2017 in forum Database Design
    Replies: 11
    Last Post: 06-27-2023, 01:47 PM
  2. Replies: 4
    Last Post: 12-22-2017, 03:44 PM
  3. Test String test besed on table data
    By igourine in forum Programming
    Replies: 3
    Last Post: 12-01-2013, 06:16 AM
  4. Automatic Flagging
    By terricritch in forum Access
    Replies: 4
    Last Post: 09-14-2010, 06:03 AM
  5. Keying in Test answers to Access DB from Written Test
    By CityOfKalamazoo in forum Access
    Replies: 3
    Last Post: 03-01-2010, 08:58 AM

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