Duplicated Records in Unbound Textboxes

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Justair07
    New Member
    • Apr 2014
    • 10

    Duplicated Records in Unbound Textboxes

    Hello everyone,

    Attached is a sample of my project to help you see the issue yourself instead of me trying to explain. It's kind of confusing.

    Once you open the db. open up the frmQuoteLog and the frmPDMontior. You will notice one record is displayed in the frmPDMonitor (Justin Ryan). This is correct.

    Now to test out the issue leave open the frmPDMonitor and frmQuoteLog at the same time. Go to frmQuotLog, go to the first record, make the "Sales Coordinator" = "Chris April", then check the box that says "Display on Product Design Monitor", then press the "Save Changes" button.

    Then look at the frmPDMonitor and you will notice the new record is now displayed on the form. This is correct as well.

    Leaving open both forms, go to frmQuoteLog and uncheck the box you previous checked on the first record, then press "Save Changes".

    Then look again at the frmPDMontior and notice that the previous record is gone but the remaining record is now duplicated.

    Only when I close the frmPDMonitor and reopen it, does the duplication go away.

    How can I avoid this duplication without closing and reopening the frmPDMonitor? The purpose of this form is to be ran 24/7.

    Sorry for the long explanation but I wanted to make sure I explained everything for the best possible solution.

    Completing this project is a top priority for me and could really use some the help.

    As always thank you,

    -Justin
    Attached Files
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    As a rule of thumb, I do not download attachments from people I don't know. Instead, please post the relevant code.

    Comment

    • Justair07
      New Member
      • Apr 2014
      • 10

      #3
      Here is the code used in a standard module in access.

      Code:
      Public Sub LoadMyForm(frm As Access.Form)
      On Error GoTo Error_Handler
      '    Dim db              As DAO.Database
          Dim rs              As DAO.Recordset
          Dim x               As Integer
      
      '    Set db = CurrentDb()
          Set rs = db.OpenRecordset("qryPDMonitor", dbOpenSnapshot)
      
          For x = 1 To 16
              If rs.EOF Then Exit For
              With frm
              frm.Controls("qn" & x) = rs!QuoteLogNumber
              frm.Controls("cust" & x) = rs!Customer
              frm.Controls("sales" & x) = rs![Sales COOrd]
              frm.Controls("prod" & x) = rs!ProductDesignInitials
              frm.Controls("submit" & x) = rs!dtmTimeSubmitted
              frm.Controls("total" & x) = rs!Expr1
              frm.Controls("c" & x) = rs!PartsCompleted
              frm.Controls("e" & x) = rs!ynExpedite
              End With
              rs.MoveNext
          Next
      
      Error_Handler_Exit:
          On Error Resume Next
          rs.Close
          Set rs = Nothing
      '    Set db = Nothing
          Exit Sub
      
      Error_Handler:
          MsgBox "The following error has occured." & vbCrLf & vbCrLf & _
                  "Error Number: " & Err.Number & vbCrLf & _
                  "Error Source: LoadMyForm" & vbCrLf & _
                  "Error Description: " & Err.Description, _
                  vbCritical, "An Error has Occured!"
          Resume Error_Handler_Exit
      End Sub
      This populates the unbound text boxes based on my query. It is ran from a Timer Event set on my frmPDMonitor
      Last edited by Rabbit; May 7 '14, 08:46 PM. Reason: fixed code tags

      Comment

      • Rabbit
        Recognized Expert MVP
        • Jan 2007
        • 12517

        #4
        Where's the code for the save changes button?

        Comment

        • Justair07
          New Member
          • Apr 2014
          • 10

          #5
          Hello Rabbit,

          Sorry for the late reply.

          Here is the code for my save changes button

          Code:
          Private Sub cmdSaveChanges_Click()
              
              On Error Resume Next
              
              If Me.Dirty Then Me.Dirty = False 'Force a save of the active record
              If (MacroError <> 0) Then
                  Beep
                  MsgBox MacroError.Description, vbOKOnly, ""
              End If
              If CurrentProject.AllForms("frmPDMonitor").IsLoaded Then Forms![frmPDMonitor].Form.Requery
          End Sub

          Comment

          • Rabbit
            Recognized Expert MVP
            • Jan 2007
            • 12517

            #6
            Is there any code that runs when you click the checkbox? If so, please post that as well. When does the LoadMyForm function get called?

            Comment

            • Justair07
              New Member
              • Apr 2014
              • 10

              #7
              Once my form is opened I use the onload event for the form to trigger a timer every second that calls the function. That's it for the code. Thank you by the way for your help with this.

              Comment

              Working...