Microsoft SQL Server
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMicrosoft SQL Server

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old February 11th, 2004, 11:17 AM
robi0193 robi0193 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 3 robi0193 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Unhappy deleting a record from multiple tables

I'm trying to develop a cmdDel button that enables a user to delete a record from 2 tables. The master form is bound to tblInvoice while the subform form (child) is bound to tblInnov (1 to 1 relationship).
Data is only being deleted in 1 table that being tblInvoice (master or main form). I'm using 2 recordsets to access each table. The form is also not being repositioned correctly after the deletion (ie: movenext or moveprevious doesn;t seem to be working). Any suggestion would be much appreciated as I'm only a beginner at VBA & would appreciate any insight. Thanks

Code:
Dim db As Database
Dim recInv As DAO.Recordset
Dim recInn As DAO.Recordset
Dim strDel As String

Set db = CurrentDb
If (Me.txtInvoiceID.Value = " " Or IsNull(Me.txtInvoiceID)) Then
MsgBox "Error: Record not updatable."
Exit Sub
End If

Set recInv = db.OpenRecordset("SELECT * FROM tblInvoice WHERE InnovId = " & Me.txtInnovID.Value, dbOpenDynaset)
Set recInn = db.OpenRecordset("SELECT * FROM tblInnov WHERE InnovId = " & Me.txtInnovID.Value, dbOpenDynaset)

If (IsNull(recInv("InnovID")) Or recInv.RecordCount <> 1) Then
MsgBox "An error occurred while retrieving record for deletion. Try again later."
Exit Sub
End If

If (recInv.Updatable = False Or recInn.Updatable = False) Then 'verify if record can be updated
MsgBox "Record cannot be updated. Sorry."
Exit Sub
End If


strDel = InputBox(Prompt:="Are you sure you wish to delete record? (y/n)", title:="Delete Record", _
xpos:=2000, ypos:=2000)
strDel = LCase$(strDel)


If (strDel = "y" Or strDel = "yes") Then
'if updatable, delete record after finding it
If (recInv.BOF) Then
recInv.Delete 'delete and then move to previous record
recInn.Delete
recInv.MoveNext
recInn.MoveNext
recInv.Close
recInn.Close
db.Close
Exit Sub
ElseIf (recInv.EOF) Then 'if first record or only record
recInv.Delete 'delete and then move to previous record
recInn.Delete
recInv.MovePrevious
recInn.MovePrevious
recInv.Close
recInn.Close
db.Close
Exit Sub
Else
recInv.Delete 'delete and then move to previous record
recInv.MoveNext
recInn.MoveNext
recInv.Close
recInn.Close
db.Close
Exit Sub
End If




ElseIf (strDel = "n" Or strDel = "no") Then
MsgBox "Deletion aborted."
recInv.Close
recInn.Close
db.Close
Exit Sub
Else
MsgBox "Invalid entry.Try again."
recInv.Close
recInn.Close
db.Close
Exit Sub
End If

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMicrosoft SQL Server > deleting a record from multiple tables


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT