Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel 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
 
Old October 12th, 2010, 08:31 AM
Registered User
 
Join Date: Feb 2010
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Delte Access record using Excel VBA

Hi

I'm trying to delete a single record in a Access database using the primary key of the record.

Code:
Dim sSQL As String

Set conn = New ADODB.Connection
conn.Provider = "Microsoft.Jet.OLEDB.4.0"
conn.Open DBsti

sSQL = "DELETE FROM IdeDB WHERE tbIde = '" & tbOpgaveNr & "'"

conn.Execute sSQL

conn.Close
Set conn = Nothing
DBsti (Path to database)
tbIde (Primary key)
tbOpgaveNr (Number (primary key) of record shown in userform)

If I change form primary key to a natural key it works fine but when I run the code I get an error from program line conn.Execute sSQL

"Runtime error 2147217904(80040e10) No value given for one or more required parameters"

I have also tried changing the code to:
Code:
sSQL = "DELETE FROM IdeDB WHERE tbIde = " & tbOpgaveNr & ""
and it is still the same.

What am I doing wrong

Last edited by Albrecht; October 12th, 2010 at 08:33 AM..
 
Old October 12th, 2010, 08:42 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

HI there..

Try "DELETE * FROM table WHERE field = " & yourcode

In access the * is mandatory for deleting rows.
__________________
HTH

Gonzalo


================================================== =========
Read this if you want to know how to get a correct reply for your question.
(Took that from Doug signature and he Took that from Peter profile)
================================================== =========
My programs achieved a new certification :
WORKS ON MY MACHINE
================================================== =========
I know that CVS was evil, and now i got the
proof.
================================================== =========
 
Old October 12th, 2010, 08:46 AM
Registered User
 
Join Date: Feb 2010
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi gbianchi

Thank you for a very quich repply. I have tried the * and it is still the same.
 
Old October 12th, 2010, 08:48 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

If you try the query in access, what field does it say that is missing?
__________________
HTH

Gonzalo


================================================== =========
Read this if you want to know how to get a correct reply for your question.
(Took that from Doug signature and he Took that from Peter profile)
================================================== =========
My programs achieved a new certification :
WORKS ON MY MACHINE
================================================== =========
I know that CVS was evil, and now i got the
proof.
================================================== =========
 
Old October 12th, 2010, 08:53 AM
Registered User
 
Join Date: Feb 2010
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hmm.. I have not tried that and I don't know much about VBA in Access. How should it look like in Access?
 
Old October 12th, 2010, 08:54 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

NO VBA in access, Can you just open the database and try the query inside of it?? usually access has a lot better error messages when you execute query inside of it...
__________________
HTH

Gonzalo


================================================== =========
Read this if you want to know how to get a correct reply for your question.
(Took that from Doug signature and he Took that from Peter profile)
================================================== =========
My programs achieved a new certification :
WORKS ON MY MACHINE
================================================== =========
I know that CVS was evil, and now i got the
proof.
================================================== =========





Similar Threads
Thread Thread Starter Forum Replies Last Post
INSERT into Access Database from VBA for Excel zuerlein Excel VBA 0 June 3rd, 2007 01:51 AM
Code works in Excel VBA but not Access VBA fossx Access VBA 2 May 21st, 2007 08:00 AM
Converting excel data to Access using excel VBA ShaileshShinde VB Databases Basics 1 April 26th, 2006 07:57 AM
ACCESS Programming DELTE problem dvlnblk2000 Access 1 September 29th, 2004 07:50 AM
Which Book for VBA/Access/SQL/Excel? rmg VB Databases Basics 0 July 29th, 2004 03:19 PM





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