Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
Password Reminder
Register
Register | FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old April 28th, 2008, 09: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
Reply With Quote
  #2 (permalink)  
Old April 29th, 2008, 08: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
Reply With Quote
  #3 (permalink)  
Old April 29th, 2008, 08: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
Reply With Quote
  #4 (permalink)  
Old May 1st, 2008, 12:38 PM
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
Reply With Quote
Reply


Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Deleting a record using SqlDataAdapter. edurazee ADO.NET 0 September 6th, 2008 07:55 AM
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 08: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



All times are GMT -4. The time now is 09:14 AM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.