474,029 Members | 27,706 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

VB Take a value from Excel to delete row from Access table

4 New Member
Hello all

I am currently trying to develop a script that will take a value from an Excel spreadsheet cell and use that to run a query against an Access table to delete all rows that match the cell.

I have tried to do this by first using a recordset and then secondly using a db.Execute (sqlstring).

The idea of using the recordset was that I thought it would return all of the records matched, however it just deletes the 1 row not all of the entries that match.

Is this just the way I have opened the recordset?

For the db.Execute I'm getting a 3061 Error - Too few parameters!

Any help truly appreciated.

Expand|Select|Wrap|Line Numbers
  1. ' exports data from the active worksheet to a table in an Access database
  2. ' exports data from the active worksheet to a table in an Access database
  3.  
  4. Dim db As DAO.Database      ' PAR History Database location/file
  5. Dim rs As DAO.Recordset     ' Table name
  6. 'Dim rs As Recordset
  7. Dim cl As Long              ' Current Line counter
  8. Dim vcurpar As String       ' Current PAR number (N2)
  9.  
  10.  
  11. vcurpar = "Notifications!N2"
  12.  
  13.  
  14.     Application.StatusBar = "Open PAR History Database"
  15.  
  16.  
  17.     ' open the database
  18.     Set db = OpenDatabase("C:\My Stuff\Projects\GCUK\PAR Change Control\PARHistory.mdb")
  19.  
  20.     ' Delete any previously PAR with this number from history.
  21.     Application.StatusBar = "Checking and removing if PAR has been archieved previously"
  22.     vtSql = "DELETE * FROM CircuitHistory WHERE parnumber = " & vcurpar & ";"
  23.  
  24.     'db.Execute (vtSql)
  25.  
  26.  
  27.  
  28.     Set rs = db.OpenRecordset("SELECT * FROM CircuitHistory WHERE CircuitHistory.parnumber = 'PAR123456'")
  29.     If Not rs.EOF Then
  30.         MsgBox (rs.RecordCount)
  31.  
  32.         rs.Delete
  33.     End If
  34.  
  35.     rs.Close
  36.  
  37.  
  38.  
  39.  
Feb 13 '07 #1
1 2374
willakawill
1,646 Top Contributor
Hi. A couple of things. When you are not assigning a return value, don't enclose your parameters in brackets as in MsgBox (rs.RecordCount ) or db.Execute (vtSql)
Secondly, in the two sql statements you have alternately referenced parnumber as numeric and textual. As the textual version seems to work in the second case here is a change to the code that will most likely work in the first case:
Expand|Select|Wrap|Line Numbers
  1. vtSql = "DELETE * FROM CircuitHistory WHERE parnumber = '" & vcurpar & "';"
Good luck
Feb 15 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

8
3390
by: mytfein | last post by:
Hi Everyone, Background: Another department intends to ftp a .txt file from the mainframe, for me to process. The objective is to write a vb script that would be scheduled to run daily to process this .txt file. Goal: I am working on a vba script to:
3
25073
by: Mads Petersen | last post by:
I'm stuck in this code. Hope you can and will help me. I launch it from excel. I have made the following code work, but not as i whant. I need the ranges to be working with something like xlDown. eg. this only transferes the first record in the area. ..Fields("Uge").Value = ws.Range("A98").Value Sub SelectMaster()
7
5398
by: Smitty | last post by:
I have a function that imports an Excel file into an Access table using SQL. I then close the OleDataReader and the OleDbConnection, then dispose the OleDbCommand, then OleDbConnection. The calling function then attempts a File.Delete (also tried the FileInfo delete) on the Excel file, but gets the message "The process cannot access the file ... because it is being used by another process". I've stepped through the code and it steps...
21
6303
by: bobh | last post by:
Hi All, In Access97 I have a table that's greater than 65k records and I'm looking for a VBA way to export the records to Excel. Anyone have vba code to export from access to excel and have the code use multiple excel tabs within a workbook???? Anyone have vba code that would create a temp table write 65,000 records to it, export those to excel, clean the temp table, append the next 65,000 records, export it to excel with a different...
6
6147
by: Niyazi | last post by:
Hi all, What is fastest way removing duplicated value from string array using vb.net? Here is what currently I am doing but the the array contains over 16000 items. And it just do it in 10 or more minutes. 'REMOVE DUBLICATED VALUE FROM ARRAY +++++++++++++++++ Dim col As New Scripting.Dictionary Dim ii As Integer = 0
12
3836
by: slinky | last post by:
Can an Excel spreadsheet or a section of one be embedded into an Access form and serve as a subform from which other parts of the Access form can get data? Thanks!
2
1877
by: John Bartley K7AAY | last post by:
When I output a table's values to XLS, one value in a very small table, and only one value, is changed. Here are the values in the table, tblLevel. LEVEL H-14 0 1 1.1
0
1634
by: Shootah | last post by:
Hi, I have succeeded in adding automated relationships with refference tables after importing an excel file created from a query to an Access database. However I have the following problem: When there are values in the excel file which was imported that do not appear in the refference tables because they are not entered yet, or in case they are misspelled, the code blocks and gives me an error message. As I am not that much of a coding...
0
3015
by: JFKJr | last post by:
I have an excel file, which has columns C and D grouped together, I am trying to delete blank columns and rows from the excel file, ungroup the columns and import the file to MS Access using Access VBA code. The following is the Access VBA code I used to delete blank columns and rows in the excel file. But, unfortunately, the resultant excel file still has two columns (C and D) grouped together, so when I am importing the file to MS Access,...
0
10512
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
11932
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10270
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
8661
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7821
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6614
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
5367
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4911
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3936
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.