place duplicate record in 2nd table

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32645

    #16
    No problem. Glad I could help.
    By the way, when running queries from the code it's often considered neater to hide any query warnings that indicate how many records are deleted / copied etc. If you want to include that then try :
    Code:
    Call DoCmd.SetWarnings(False)
    'Query(ies) here
    Call DoCmd.SetWarnings(True)

    Comment

    • shaffy08
      New Member
      • Dec 2007
      • 20

      #17
      so my code will look like this? if so, it didn't work.
      Code:
      Call DoCmd.SetWarnings(False)
      Private Sub add_Click()
      On Error GoTo Err_add_Click
       
          Call DoCmd.RunCommand(acCmdRecordsGoToNext)
          DoCmd.OpenQuery "NOI", acNormal, acEdit
          DoCmd.OpenQuery "delete", acNormal, acEdit
          Call DoCmd.RunCommand(acCmdRecordsGoToPrevious)
       
      Exit_add_Click:
          Exit Sub
       
      Err_add_Click:
          MsgBox Err.Description
          Resume Exit_add_Click
      
      Call DoCmd.SetWarnings(True)
      End Sub

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32645

        #18
        Not exactly. The only code between the two new lines is the queries.
        IE :
        Code:
        Private Sub add_Click()
        On Error GoTo Err_add_Click
        
            Call DoCmd.RunCommand(acCmdRecordsGoToNext)
            [U]Call DoCmd.SetWarnings(False)[/U]
            DoCmd.OpenQuery "NOI", acNormal, acEdit
            DoCmd.OpenQuery "delete", acNormal, acEdit
            [U]Call DoCmd.SetWarnings(True)[/U]
            Call DoCmd.RunCommand(acCmdRecordsGoToPrevious)
        
        Exit_add_Click:
            Exit Sub
        
        Err_add_Click:
            MsgBox Err.Description
            Resume Exit_add_Click
        
        End Sub

        Comment

        • shaffy08
          New Member
          • Dec 2007
          • 20

          #19
          Thanks! it works great. Is there a way to move automatically to next record after deletion...as of right now, it shows #delete in the fields?

          Comment

          • NeoPa
            Recognized Expert Moderator MVP
            • Oct 2006
            • 32645

            #20
            Try the following after the code that does the work :
            Code:
            Call Me.ReQuery()

            Comment

            • shaffy08
              New Member
              • Dec 2007
              • 20

              #21
              nope. that didn't work :(

              Comment

              • PianoMan64
                Recognized Expert Contributor
                • Jan 2008
                • 374

                #22
                just ry me.requery at the end off that sub routine

                Comment

                • NeoPa
                  Recognized Expert Moderator MVP
                  • Oct 2006
                  • 32645

                  #23
                  Originally posted by shaffy08
                  nope. that didn't work :(
                  So what does it do? What did you notice?

                  Comment

                  • shaffy08
                    New Member
                    • Dec 2007
                    • 20

                    #24
                    Originally posted by NeoPa
                    So what does it do? What did you notice?
                    it works now :-) I was placing it at the wrong place - I was placing it after the code that hide the warring message instead of right after the code that runs the delete query.

                    thanks for the help.

                    Comment

                    • NeoPa
                      Recognized Expert Moderator MVP
                      • Oct 2006
                      • 32645

                      #25
                      No worries Shaffy. I'm pleased you got it sorted :)

                      Comment

                      Working...