Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
| Search | Today's Posts | Mark Forums Read
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old April 28th, 2008, 08:11 AM
Registered User
 
Join Date: Apr 2008
Location: pearland, texas, USA.
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to captainlove
Default Deleting a record from a subform

Here is my code, to delete a record from a subform from the main form, but it is not working. The error is user defined type not defined.
Private Sub cmdinsertlist_Click()

Dim Rs As DAO.Recordset
Set Rs = CurrentDb.OpenRecordset("Select * From tblrefLink Where refID = " & Me.ID & " And UserID = '" & Forms.frmqcpList2.txtQcp & "'")

If Not Rs.EOR Or Not Rs.BOF Then
    Do Until Rs.EOF
       Rs.Delete
       Rs.Update
       Rs.MoveNext
   Loop
   Rs.Close
End If

Set Rs = Nothing


End Sub

lucasfatoye
  #2 (permalink)  
Old April 29th, 2008, 07:06 AM
Friend of Wrox
Points: 9,611, Level: 42
Points: 9,611, Level: 42 Points: 9,611, Level: 42 Points: 9,611, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2004
Location: Washington, DC, USA.
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

It is generally not a good idea to take values into SQL strings at runtime. Try this instead (make sure UserID is text, not an integer.

Dim Rs As DAO.Recordset
Dim sSQL As String
Dim lRefID As Long
Dim lUserID As Long

lRefID = Me.ID
lUserID = Forms.frmqcpList2.txtQcp

sSQL = ("Select * From tblrefLink Where refID = " & lRefID & " And UserID = '" & lUserID & "'"

Set Rs = CurrentDb.OpenRecordset(sSQL)

If the problem is in the reference to a subform for lUserID, then you might need to do something like:

lUserID = [Forms]![frmMainFormName]![sfrmSubFormName].[txtTextControlName]

since the subform is an object or control on the main form. Main form / sub form Bang Dot notation is pretty kludgey in Access. I always have problems with this issue.

mmcdonal

Look it up at: http://wrox.books24x7.com
  #3 (permalink)  
Old April 29th, 2008, 07:07 AM
Friend of Wrox
Points: 9,611, Level: 42
Points: 9,611, Level: 42 Points: 9,611, Level: 42 Points: 9,611, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2004
Location: Washington, DC, USA.
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Sorry, this:

sSQL = ("Select * From tblrefLink Where refID = " & lRefID & " And UserID = '" & lUserID & "'"

should be:

sSQL = "Select * From tblrefLink Where refID = " & lRefID & " And UserID = '" & lUserID & "'"


mmcdonal

Look it up at: http://wrox.books24x7.com
  #4 (permalink)  
Old May 1st, 2008, 11:38 AM
Registered User
 
Join Date: Apr 2008
Location: pearland, texas, USA.
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to captainlove
Default

Thanks, I think that works

lucasfatoye


Similar Threads
Thread Thread Starter Forum Replies Last Post
Deleting All Record In A Table McDiddy Access VBA 3 January 10th, 2007 09:20 AM
Deleting A Record sirmilt BOOK: Beginning Visual Basic 2005 Databases ISBN: 978-0-7645-8894-5 1 July 31st, 2006 07:12 PM
updating and deleting record PinkyCat Classic ASP Databases 4 March 16th, 2005 05:50 AM
Deleting a record AND the images? jonpanky MySQL 0 January 4th, 2005 12:13 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.