Results 1 to 4 of 4

Thread: please what is wrong with this code

  1. #1

    Thread Starter
    Lively Member nutstretch's Avatar
    Join Date
    May 2000
    Location
    UK
    Posts
    85

    please what is wrong with this code

    I have some code which is supposed to delete a customer all related pets and thier related infomation and delete all future booking which belong to the customer about to be deleted.

    It is deleting most of the records but does not delete the booking details records. The booking is deleted but not the records which are related to the booking.

    Please look at the code and see if you can find something wrong with it


    Dim nReply As Integer ' declare a reply to a message box
    'show a message box checking that these details should be deleted
    nReply = MsgBox("Are you sure you want to delete this customer?", vbYesNo + vbQuestion, "Confirm delete")
    If nReply = vbYes Then 'if the yes button is pressed then continue
    Set db = OpenDatabase(App.Path & "\kennel.mdb")
    db.Execute ("delete * from tblCustomer where cust_no =" & cust_no) ' delete all from that row where that is the index no
    'frmFamily.Data1.Refresh ' refresh the form and data control
    Set rs = db.OpenRecordset("select * from tblpet_details where cust_no = " & cust_no)
    If Not rs.EOF Then
    Do While Not rs.EOF
    pet_no = rs("pet_no")
    db.Execute ("delete * from tblDiet where pet_no = " & pet_no)
    db.Execute ("delete * from tblmedication where pet_no = " & pet_no)
    db.Execute ("delete * from tblAttention where pet_no = " & pet_no)
    rs.MoveNext
    Loop
    End If

    Set rs = db.OpenRecordset("select * from qbooking where cust_no = " & cust_no)
    If Not rs.EOF Then
    Do While Not rs.EOF
    bookNo = rs("booking_no")
    db.Execute ("delete * from tblBooking_details where booking_no = " & bookNo)
    db.Execute ("delete * from tblpet_addons where booking_no = " & bookNo)
    rs.MoveNext
    Loop
    End If
    db.Execute ("Delete * from tblbooking where booking_no = " & bookNo)


    db.Execute ("delete * from tblpet_details where cust_no = " & cust_no)
    if at first you don't succeed, drink the rest of the bottle and loop to the same place tomorrow

  2. #2

    Thread Starter
    Lively Member nutstretch's Avatar
    Join Date
    May 2000
    Location
    UK
    Posts
    85

    resolved

    stupid me how can you find a record in a query if you delete the custome form the table first!!!!!!
    if at first you don't succeed, drink the rest of the bottle and loop to the same place tomorrow

  3. #3
    PowerPoster
    Join Date
    Nov 2001
    Location
    Trying to reach and stay in the cloud
    Posts
    2,089

    hi

    So is it solved?

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    VB Code:
    1. Dim Db As Database
    2. Dim nReply As Integer ' declare a reply to a message box
    3. 'show a message box checking that these details should be deleted
    4. nReply = MsgBox("Are you sure you want to delete this customer?", vbYesNo + vbQuestion, "Confirm delete")
    5. If nReply = vbYes Then 'if the yes button is pressed then continue
    6.         Set Db = OpenDatabase(App.Path & "\kennel.mdb")
    7.         Db.Execute ("delete * from tblCustomer where cust_no =" & cust_no) ' delete all from that row where that is the index no
    8.         'frmFamily.Data1.Refresh ' refresh the form and data control
    9.         Set rs = Db.OpenRecordset("select * from tblpet_details where cust_no = " & cust_no)
    10.     If Not rs.EOF Then
    11.         Do While Not rs.EOF
    12.             pet_no = rs("pet_no")
    13.             Db.Execute ("delete * from tblDiet where pet_no = " & pet_no)
    14.             Db.Execute ("delete * from tblmedication where pet_no = " & pet_no)
    15.             Db.Execute ("delete * from tblAttention where pet_no = " & pet_no)
    16.             rs.MoveNext
    17.         Loop
    18.     End If
    19.    
    20.     Set rs = Db.OpenRecordset("select * from qbooking where cust_no = " & cust_no)
    21.     If Not rs.EOF Then
    22.         Do While Not rs.EOF
    23.             bookNo = rs("booking_no")
    24.             Db.Execute ("delete * from tblBooking_details where booking_no = " & bookNo)
    25.             Db.Execute ("delete * from tblpet_addons where booking_no = " & bookNo)
    26.         rs.MoveNext
    27.         Loop
    28.     End If
    29.     Db.Execute ("Delete * from tblbooking where booking_no = " & bookNo)
    30.     Db.Execute ("delete * from tblpet_details where cust_no = " & cust_no)
    I don't see an End If for the If nReply

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width