When a Record deleted, WOULD like it to go into a DELETED TABLE

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • DavidOwens
    New Member
    • Mar 2007
    • 56

    When a Record deleted, WOULD like it to go into a DELETED TABLE

    Hi there everybody

    iv designed a database, curently when the delete button is pushed, it deletes the record completly, but i dont want that i want it to just disable the dispenser.

    iv crreated, a column in the dispenser table and put the disabled sipensers to NO or Y, i have created a disabled and NOT disabled query.

    select * dispensers
    where dispensers.disa bled="no"

    or

    select * dispensers
    where dispensers.disa bled="Y".

    so i have also, but this bit of sql in other queries, were i ws to just display the dispensers who are active, but when i go to a report and click privew, a PARAMETER BOX opens and asks for DISPENSER.DISAB LED, i ut in Y or NO, but it just does the same thing or errors,

    below is the code for when the preview button is pushed

    Sub PreviewReport_C lick()
    On Error GoTo Err_PreviewRepo rt_Click

    Dim stRepName As String: Rem Holds the Report name
    Dim stDispId As String: Rem Holds the Dispenser ID
    Dim stQuery As String: Rem Holds the Query name
    Dim stWhere As String: Rem Holds the where clause
    Dim stExtra As String:
    Dim stMonthYear, stYear, stWeekCount As String
    Dim intX As Integer, rst As Recordset
    Dim dtEndDate As Date

    stRepName = Form.cbReports

    If IsNull(Form.cbD ispenser) Then
    MsgBox ("Please pick a Dispenser.")
    GoTo Exit_PreviewRep ort_Click
    End If

    stDispId = Form.cbDispense r
    stWhere = ""

    If IsNull(Form.cbM onthYear) Then
    MsgBox ("Please pick a Month")
    GoTo Exit_PreviewRep ort_Click
    Else
    stMonthYear = Form.cbMonthYea r
    stYear = Format(CDate("1 " & Form.cbMonthYea r), "yyyy")
    End If


    dtEndDate = Nz(DMax("EndDat e", "Dispensers ", "[ID] = " & stDispId), cLowDate)






    If stRepName = "Weekly Dispenser Sales" Then
    stQuery = "Weekly Dispenser Sales"
    stWhere = "format(START_D T,""MMMM YYYY"") = """ + stMonthYear + """"
    ElseIf stRepName = "Individual Weekly Sales" Then: Rem Sheet 8
    If dtEndDate <> cLowDate And _
    Format(dtEndDat e, "YYYYMMDD") < Format(CDate(cb MonthYear), "YYYYMMDD") Then

    MsgBox ("There are no records for this Dispenser in this month")
    Exit Sub

    Else
    stQuery = "Individual Weekly Sales"
    stExtra = "DISPENSERS.Dis abled = ""no"" "
    stWhere = "SALES.DISPENSE R_ID = " + stDispId + " and format(START_DT ,""MMMM YYYY"") = """ + stMonthYear + """ and "DISPENSERS.Dis abled = ""no"" """""""
    End If
    ElseIf stRepName = "Company Weekly Sales" Then
    stQuery = "Company Weekly Sales"
    stExtra = " AND DISPENSERS.Disa bled = ""no"" "
    stWhere = "MonthYear= """ + stMonthYear + """" + stExtra
    ElseIf stRepName = "Company Monthly Sales" Then
    stQuery = "Company Monthly Sales"
    stWhere = "Year= " & stYear
    ElseIf stRepName = "Company Year End" Then
    stQuery = "Company Year End"
    stWhere = "SALES.WorkingW eek=-1"
    ElseIf stRepName = "Dispenser Comparison Monthly" Then: Rem Sheet 11
    stQuery = "Dispenser Comparison Monthly"
    stWhere = "MonthYear= """ + stMonthYear + """"
    ElseIf stRepName = "Dispenser Comparison Yearly" Then
    stQuery = "Dispenser Comparison Yearly"
    stWhere = "Year= " & stYear & " and SALES.WorkingWe ek =-1"
    ElseIf stRepName = "Individual Monthly Sales" Then
    If dtEndDate <> cLowDate And _
    Format(dtEndDat e, "YYYY") < Format(CDate(cb MonthYear), "YYYY") Then

    MsgBox ("There are no records for this Dispenser in this year")
    Exit Sub
    Else
    stQuery = "Individual Monthly Sales"
    stWhere = "DISPENSER_ ID=" & stDispId & " and Year = " & stYear
    End If
    ElseIf stRepName = "Individual Year End" Then
    stQuery = "Individual Year End"
    stWhere = "DISPENSERI D=" & stDispId & " and SALES.WorkingWe ek = -1"
    End If

    DoCmd.OpenRepor t stRepName, acPreview, stQuery, stWhere

    Exit_PreviewRep ort_Click:
    Exit Sub

    Err_PreviewRepo rt_Click:
    MsgBox Err.Description
    Resume Exit_PreviewRep ort_Click

    End Sub


    HELP ME GUYS........... ....HEEEELLLLPP PP. i have tried defining DISPENSER.DISAB LED as stEXTRA as you can see, but im not sure how to write the syntax or even if im doing it right.
  • DavidOwens
    New Member
    • Mar 2007
    • 56

    #2
    When a Record deleted, WOULD like it to go into a DELETED TABLE

    Hey Guys, im having trouble doign something

    i have a table of dispensers, also have a main menu, on the menu it has a button were you can amend dispensers, also delete them.

    but instead of deleting the member, i would like it to take the member out of the dispenser table and inseart it into a deleted dispenser table, any ideas?

    please help, my brain is rattled. cheers guys and girls.

    Comment

    • missinglinq
      Recognized Expert Specialist
      • Nov 2006
      • 3533

      #3
      Use an Append Query to add the record to the "Delete" table, then delete the record! Depending on your situation, you might consider adding a field to the Delete table for the deletion date. Set the Default Value in the field's definition to Now() or Date() depending on whether you want just the date or date and time.

      Comment

      • DavidOwens
        New Member
        • Mar 2007
        • 56

        #4
        Originally posted by missinglinq
        Use an Append Query to add the record to the "Delete" table, then delete the record! Depending on your situation, you might consider adding a field to the Delete table for the deletion date. Set the Default Value in the field's definition to Now() or Date() depending on whether you want just the date or date and time.

        lol thats a bit over my head:(:(, im new to all this, just really want the dispense moved from the dispenser table to dispsenser deleted table when delete is clicked.

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32645

          #5
          I started to read this, then saw why there was no reply posted.
          Code, when provided, needs to be in tags, readable, no longer than necessary and is an accompaniment to a well explained question (See POSTING GUIDELINES: Please read carefully before posting to a forum). Your explanation skips from one unexplained concept to another, mid-sentence.
          I suggest if you want a response, you consider adding another post in here that gives our experts at least a fighting chance of helping you.

          MODERATOR.

          Comment

          • DavidOwens
            New Member
            • Mar 2007
            • 56

            #6
            disableing a user, not deleting it completly and posting it into new table

            i have a main form that loads up when my database loads, when you click the delete dispenser button, it changes the value of the dispenser to Y meaning its beeen disabled, but i would like it to go into a table called disabled dispensers and disappear from the dispensers table.

            ideas please guys?? if you require to see some code, i havent got any here now, but will post when i get back to work 2morrow.

            thanks guys.

            Comment

            • MMcCarthy
              Recognized Expert MVP
              • Aug 2006
              • 14387

              #7
              Originally posted by DavidOwens
              i have a main form that loads up when my database loads, when you click the delete dispenser button, it changes the value of the dispenser to Y meaning its beeen disabled, but i would like it to go into a table called disabled dispensers and disappear from the dispensers table.

              ideas please guys?? if you require to see some code, i havent got any here now, but will post when i get back to work 2morrow.

              thanks guys.
              Hi David

              I'm afraid double posting of questions is frowned on so I'm going to merge this with the previous question.

              Mary

              Comment

              • MMcCarthy
                Recognized Expert MVP
                • Aug 2006
                • 14387

                #8
                OK now to answer your question.

                When the value of the status field changes to Y. Then add this code to the delete button.
                Code:
                Dim strSQL As String
                
                   strSQL = "INSERT INTO [Deleted Dispensers] (Field1, Field2, Field3) " & _
                	   "SELECT Field1, Field2, Field3 FROM Dispensers WHERE Status='Y';"
                   DoCmd.RunSQL strSQL
                   
                   strSQL = "DELETE FROM Dispensers WHERE Status='Y';"
                   DoCmd.RunSQL

                Mary

                Comment

                • MMcCarthy
                  Recognized Expert MVP
                  • Aug 2006
                  • 14387

                  #9
                  Not to disagree with the moderator in any way but I'm merging this post as I did the previous one. This is three posts for one question David. Stick to one post in future and if you are not getting attention after 24 hours then post a reply to it to bump it up the list.

                  ADMIN

                  Comment

                  • DavidOwens
                    New Member
                    • Mar 2007
                    • 56

                    #10
                    Originally posted by mmccarthy
                    OK now to answer your question.

                    When the value of the status field changes to Y. Then add this code to the delete button.
                    Code:
                    Dim strSQL As String
                    
                       strSQL = "INSERT INTO [Deleted Dispensers] (Field1, Field2, Field3) " & _
                    	   "SELECT Field1, Field2, Field3 FROM Dispensers WHERE Status='Y';"
                       DoCmd.RunSQL strSQL
                       
                       strSQL = "DELETE FROM Dispensers WHERE Status='Y';"
                       DoCmd.RunSQL

                    Mary

                    HI Mary

                    thanks for the help so far, but i have tried that as you can see below

                    Private Sub pb_Delete_Click ()


                    On Error GoTo Err_pb_Delete_C lick

                    Dim strSQL As String

                    strSQL = "INSERT INTO [Deleted Dispensers] (FORNAME, SURNAME, ADDR1, ADDR2, ADDR3, ADDR4, PostCode, Home_No, Mobile_No, StartDate, FullTime, EndDate, Disabled) " & _
                    "SELECT FORNAME, SURNAME, ADDR1, ADDR2, ADDR3, ADDR4, PostCode, Home_No, Mobile_No, StartDate, FullTime, EndDate, Disabled FROM Dispensers WHERE Status='Y';"
                    DoCmd.RunSQL strSQL

                    strSQL = "DELETE FROM Dispensers WHERE Status='Y';"
                    DoCmd.RunSQL


                    Exit_pb_Delete_ Click:
                    Exit Sub

                    Err_pb_Delete_C lick:
                    MsgBox Err.Description
                    Resume Exit_pb_Delete_ Click


                    but i get an error COMPILE ERROR - ARGUMENT NOT OPTIONAL and it points back to this line DoCmd.RunSQL??? ?

                    any ideas??

                    Comment

                    • MMcCarthy
                      Recognized Expert MVP
                      • Aug 2006
                      • 14387

                      #11
                      Should be ...
                      Code:
                      Private Sub pb_Delete_Click()
                      On Error GoTo Err_pb_Delete_Click
                      Dim strSQL As String
                      
                         strSQL = "INSERT INTO [Deleted Dispensers] (FORNAME, SURNAME, ADDR1, ADDR2, ADDR3, ADDR4, PostCode, Home_No, Mobile_No, StartDate, FullTime, EndDate, Disabled) " & _
                             "SELECT FORNAME, SURNAME, ADDR1, ADDR2, ADDR3, ADDR4, PostCode, Home_No, Mobile_No, StartDate, FullTime, EndDate, Disabled FROM Dispensers WHERE Status='Y';"
                         DoCmd.RunSQL strSQL
                         
                         strSQL = "DELETE FROM Dispensers WHERE Status='Y';"
                         DoCmd.RunSQL strSQL
                      
                          Exit_pb_Delete_Click:
                          Exit Sub
                      
                      Err_pb_Delete_Click:
                          MsgBox Err.Description
                          Resume Exit_pb_Delete_Click
                      
                      End Sub
                      Mary

                      Comment

                      • DavidOwens
                        New Member
                        • Mar 2007
                        • 56

                        #12
                        Originally posted by mmccarthy
                        Should be ...
                        Code:
                        Private Sub pb_Delete_Click()
                        On Error GoTo Err_pb_Delete_Click
                        Dim strSQL As String
                        
                           strSQL = "INSERT INTO [Deleted Dispensers] (FORNAME, SURNAME, ADDR1, ADDR2, ADDR3, ADDR4, PostCode, Home_No, Mobile_No, StartDate, FullTime, EndDate, Disabled) " & _
                               "SELECT FORNAME, SURNAME, ADDR1, ADDR2, ADDR3, ADDR4, PostCode, Home_No, Mobile_No, StartDate, FullTime, EndDate, Disabled FROM Dispensers WHERE Status='Y';"
                           DoCmd.RunSQL strSQL
                           
                           strSQL = "DELETE FROM Dispensers WHERE Status='Y';"
                           DoCmd.RunSQL strSQL
                        
                            Exit_pb_Delete_Click:
                            Exit Sub
                        
                        Err_pb_Delete_Click:
                            MsgBox Err.Description
                            Resume Exit_pb_Delete_Click
                        
                        End Sub
                        Mary

                        that amlost works, just had to change status to diabled, but not i want the dispensers table to be updated and the dispensers that have been disbled to be taken out of der

                        i know the code is something like

                        UPDATE Dispensers SET and the field names??? but not sure.

                        but you have been very helpful so far,thank you

                        Comment

                        • MMcCarthy
                          Recognized Expert MVP
                          • Aug 2006
                          • 14387

                          #13
                          Originally posted by DavidOwens
                          that amlost works, just had to change status to diabled, but not i want the dispensers table to be updated and the dispensers that have been disbled to be taken out of der

                          i know the code is something like

                          UPDATE Dispensers SET and the field names??? but not sure.

                          but you have been very helpful so far,thank you
                          David

                          The second DELETE statement should have deleted them from the dispensers table.

                          Mary

                          Comment

                          • DavidOwens
                            New Member
                            • Mar 2007
                            • 56

                            #14
                            hi, no it doesnt delete, it just copies them into the deleted dispensers table.but leaves them in the dispensers, is that because the UPDATE is not used??

                            Comment

                            • MMcCarthy
                              Recognized Expert MVP
                              • Aug 2006
                              • 14387

                              #15
                              Originally posted by DavidOwens
                              hi, no it doesnt delete, it just copies them into the deleted dispensers table.but leaves them in the dispensers, is that because the UPDATE is not used??
                              Try changing it to this
                              Code:
                              strSQL = "DELETE * FROM Dispensers WHERE Status='Y';"
                              DoCmd.RunSQL strSQL
                              Mary

                              Comment

                              Working...