Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
runtime 3021
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Kevin  
View profile  
 More options Nov 4, 12:00 pm
Newsgroups: microsoft.public.access
From: Kevin <kevin.pt...@yahoo.com>
Date: Tue, 3 Nov 2009 17:00:08 -0800 (PST)
Local: Wed, Nov 4 2009 12:00 pm
Subject: runtime 3021
i am trying to delete an item from a list box by clicking on a
button.  It's not working, obviously but the problem is that I dont
know why.  I have this same code for list box 1 and it works just
fine.  this one errors out on rst.delete with runtime 3021 : no
current record.  What am i doing wrong??

Private Sub Command3_Click()
'delete from list box2
Dim rst As DAO.Recordset
Set rst = CurrentDb.OpenRecordset("SELECT * FROM account WHERE
'account type' = '" & Me.list2 & "'")
rst.Delete
Me.list2.Requery

End Sub


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Dirk Goldgar  
View profile  
 More options Nov 4, 2:55 pm
Newsgroups: microsoft.public.access
From: "Dirk Goldgar" <d...@NOdataSPAMgnostics.com.invalid>
Date: Tue, 3 Nov 2009 22:55:57 -0500
Local: Wed, Nov 4 2009 2:55 pm
Subject: Re: runtime 3021
"Kevin" <kevin.pt...@yahoo.com> wrote in message

news:62bf611e-271c-488c-a83f-d34703b86428@a31g2000yqn.googlegroups.com...

Your SQL statement incorrectly puts quotes around the [account type] field.
If you are going to do it via a recordset like that, this would be better:

'------ start of amended code #1 ------
Private Sub Command3_Click()

    Dim rst As DAO.Recordset

    With Me.list2

        If Not IsNull(.Value) Then

            Set rst = CurrentDb.OpenRecordset( _
                "SELECT * FROM account WHERE [account type] = '" & _
                .Value & "'")

            rst.Delete
            rst.Close

        End If

        .Requery

    End With

End Sub
'------ end of amended code #1 ------

However, that is not the best way to do it.  This would be better:

'------ start of amended code #2 ------
Private Sub Command3_Click()

    With Me.list2

        If Not IsNull(.Value) Then

            CurrentDb.Execute _
                "DELETE FROM account WHERE [account type] = '" & _
                    .Value & "'", _
                dbFailOnError

        End If

        .Requery

    End With

End Sub
'------ end of amended code #2 ------

--
Dirk Goldgar, MS Access MVP
Access tips: www.datagnostics.com/tips.html

(please reply to the newsgroup)


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Tom van Stiphout  
View profile  
 More options Nov 4, 3:23 pm
Newsgroups: microsoft.public.access
From: Tom van Stiphout <tom7744.no.s...@cox.net>
Date: Tue, 03 Nov 2009 21:23:08 -0700
Local: Wed, Nov 4 2009 3:23 pm
Subject: Re: runtime 3021
On Tue, 3 Nov 2009 22:55:57 -0500, "Dirk Goldgar"

<d...@NOdataSPAMgnostics.com.invalid> wrote:

I agree the [ ] are better than what was there before, but the real
issue with the Recordset approach is that it does not test for EOF:
set rst = CurrentDB.OpenRecordset(...)
if rst.EOF then
  Msgbox "Alarm: No record found. Unable to delete unfound record!"
else
  rst.Delete ...

Your suggested Delete statement is OK, but better would be to run a
Delete query. I consider that better because it eliminates
hard-to-maintain inline SQL.
dim qd as dao.querydef
set qd = currentdb.querydefs("myDeleteQuery")
qd!myFirstParameter = ...
qd.Execute dbFailOnError

-Tom.
Microsoft Access MVP


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Dirk Goldgar  
View profile  
 More options Nov 5, 1:50 am
Newsgroups: microsoft.public.access
From: "Dirk Goldgar" <d...@NOdataSPAMgnostics.com.invalid>
Date: Wed, 4 Nov 2009 09:50:24 -0500
Local: Thurs, Nov 5 2009 1:50 am
Subject: Re: runtime 3021
"Tom van Stiphout" <tom7744.no.s...@cox.net> wrote in message
news:n302f5dpa2ii86g11gdtu0c525162e3s5l@4ax.com...

> On Tue, 3 Nov 2009 22:55:57 -0500, "Dirk Goldgar"
> <d...@NOdataSPAMgnostics.com.invalid> wrote:

> I agree the [ ] are better than what was there before, but the real
> issue with the Recordset approach is that it does not test for EOF:
> set rst = CurrentDB.OpenRecordset(...)
> if rst.EOF then
>  Msgbox "Alarm: No record found. Unable to delete unfound record!"
> else
>  rst.Delete ...

You're right that the code ought to check for EOF, just in case, so as to
give a less obscure error message.  However, I concluded from the problem
description that the record *must* exist in the table, since it is displayed
in the list box.  Therefore, the primary problem is that the recordset isn't
finding a record when the record exists.

--
Dirk Goldgar, MS Access MVP
Access tips: www.datagnostics.com/tips.html

(please reply to the newsgroup)


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google