473,385 Members | 1,940 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Can't update access table that contains space from Excel VBA

1
I am developing an application in Ms Excel 2003 that has a feature to update records in Ms Access. The problem is the table name I am trying to update contains a space and whenever I run the below code I got the following Error Message.

[Microsoft][ODBC Microsoft Access Driver] Invalid SQL statement; expected ‘DELETE’, ‘INSERT’, ‘PROCEDURE’, ‘SELECT, OR ‘UPDATE’

However, I can’t rename the table because it has many relationships and connections with other tables.

Private Sub CommandButton1_Click()

On Error Resume Next

Dim adoconn As ADODB.Connection
Dim adors As ADODB.Recordset


Set adoconn = New ADODB.Connection
adoconn.Open "Provider=MSDASQL.1;Persist Security Info=False;Data Source=Requirements"


Set adors = New ADODB.Recordset

adors.Open "[EmployeeList1]", adoconn, adOpenDynamic, adLockOptimistic

MsgBox Err.Description
MsgBox Err.Source

Do While Not adors.EOF

If adors.Fields("`Ey Number`").Value = Range("A1").Value Then
adors.Fields("`Ey Number`").Value = "123"

Exit Do

End If
adors.MoveNext
Loop
adors.Update
adors.Close
End Sub



Could you help me to sort out this problem?
Nov 13 '08 #1
1 3809
MikeTheBike
639 Expert 512MB
I am developing an application in Ms Excel 2003 that has a feature to update records in Ms Access. The problem is the table name I am trying to update contains a space and whenever I run the below code I got the following Error Message.

[Microsoft][ODBC Microsoft Access Driver] Invalid SQL statement; expected ‘DELETE’, ‘INSERT’, ‘PROCEDURE’, ‘SELECT, OR ‘UPDATE’

However, I can’t rename the table because it has many relationships and connections with other tables.

Private Sub CommandButton1_Click()

On Error Resume Next

Dim adoconn As ADODB.Connection
Dim adors As ADODB.Recordset


Set adoconn = New ADODB.Connection
adoconn.Open "Provider=MSDASQL.1;Persist Security Info=False;Data Source=Requirements"


Set adors = New ADODB.Recordset

adors.Open "[EmployeeList1]", adoconn, adOpenDynamic, adLockOptimistic

MsgBox Err.Description
MsgBox Err.Source

Do While Not adors.EOF

If adors.Fields("`Ey Number`").Value = Range("A1").Value Then
adors.Fields("`Ey Number`").Value = "123"

Exit Do

End If
adors.MoveNext
Loop
adors.Update
adors.Close
End Sub



Could you help me to sort out this problem?
Hi

Just a thought, but if "EmployeeList1" is a query (?) then you need this

adors.Open "SELECT * FROM EmployeeList1", adoconn, adOpenDynamic, adLockOptimistic


Also, does your field name actualy have apostrophies, if not, then you do not need then, just

adors.Fields("Ey Number")

should do it.


??


MTB
Nov 13 '08 #2

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

Similar topics

12
by: jimserac | last post by:
I had previously posted this in an Access forum with negative results so will try here. Although this question specifies an Access database, I also wish to accomplish this with a large MS SQL...
4
by: Kathleen Turner | last post by:
I have an Excel file that has list of serial numbers followed by a 4 digit code. I have an Access database that has the serial numbers but the field for the 4 digit code is either blank, has the 4...
10
by: Randy Harris | last post by:
I imported records into a table, later found out that many of them had trailing spaces in one of the fields. If I'd caught it sooner, I could have trimmed the spaces before the import. This...
7
by: MLH | last post by:
Building Applications with Microsoft Access 97 is a publication I think I need. Is it available in book form? Is MicroSoft the sole vendor? Anybody got a copy they wanna sell???
2
by: Acephalus | last post by:
I am currently using this to get data from an .xls file:string conn = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + file + ";" + "Extended Properties=Excel 8.0;";...
3
by: ninrulz | last post by:
I will try to explain my situation. I know that it is hard to offers solutions without fully understanding what people would like to achieve. I receive 2 csv files every month. The csv files...
2
by: ruthboaz | last post by:
Hi, I am exporting a table with data to an excel file.. Some fields are empty in the exported file while the others and the key field, has values. The empty field(s) in excel, will be entered...
4
by: christianlott1 | last post by:
I've linked an excel worksheet as an access table. The values appear but it won't allow me to change any of the values. To test I've provided a fresh blank workbook and same problem. I've done...
6
by: provor | last post by:
Hello, I have the following code that I am using when a user presses a button to import an excel file into a table. The code is hard coded to point to the correct table. This works great for this...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.