473,406 Members | 2,371 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,406 software developers and data experts.

VBA modify a table with the SQL Alter Statement Syntax Error

133 100+
A field needs to be modified from text to date after importing from a CSV file. the CSV does not acknowledge the date/time field through the import specification. therefore, a routine needs to be added immediately following the import of the CSV file.

I have encounter a couple of ways to perform this routine. I have success when changing only one field in the following code.

Expand|Select|Wrap|Line Numbers
  1. strSQL = "ALTER TABLE PODataFull ALTER COLUMN [Workflow Completion Date] DATETIME;"
  2.  
However, when i attempted to alter multiple fields within a table using an SQL statement, a syntax error is generated.

Expand|Select|Wrap|Line Numbers
  1. strSQL = "ALTER TABLE PODataFull " & _
  2.             "MODIFY ([Workflow Completion Date] DATE, " & _
  3.                     "[PO Closed Date] DATE);"
  4.  
Any help would be appreciated.

mary
May 25 '11 #1
4 2510
ADezii
8,834 Expert 8TB
Not positive if can can Modify Multiple Fields within a single SQL Statement, but the following Syntax will work:
Expand|Select|Wrap|Line Numbers
  1. Dim strSql As String
  2. Dim strSql2 As String
  3.  
  4. strSql = "ALTER TABLE tblData ALTER COLUMN Field1 DATE;"
  5.   DBEngine(0)(0).Execute strSql, dbFailOnError
  6.  
  7. strSql2 = "ALTER TABLE tblData ALTER COLUMN Field2 DATE;"
  8.   DBEngine(0)(0).Execute strSql2, dbFailOnError
May 25 '11 #2
dowlingm815
133 100+
Good morning ADezii,

thank you for your prompt reply. i was hoping for multiple updates. i can't understand why the SQL can't translate VBA as in the second set of code which was obtained from this site:

** Edit ** Illegal link removed.
May 25 '11 #3
ADezii
8,834 Expert 8TB
Not sure what is going on, since the MODIFY Statement does not show up as an Option with ALTER TABLE for either Jet or Transact SQL.
May 25 '11 #4
NeoPa
32,556 Expert Mod 16PB
ADezii,s quite right Mary. That syntax is not supported in Jet SQL. For help with that see Finding Jet SQL Help.

Please remember when reporting a problem to include the error message as well as the number and the code that errored (The line is generally identified by the yellow highlight if you select Debug).

PS The link you included was not for Access (Now removed as it breaks the site rules).
May 25 '11 #5

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

Similar topics

4
by: gregpinero | last post by:
It's the strangest thing, I'm pulling some text out of a MySQL table and trying to run exec on it, and it keeps giving me a syntax error, always at the end of the first line. Thanks in advance...
4
by: tasmontique | last post by:
Hello everyone, I keep getting a syntax error in my update statement. The only thing that I notice is that although the columns in my table have the same name as the fields on the form the...
3
by: Deano | last post by:
Hi, I just want to add a text column to a table in my code. I can't find a simple example of this. dbs.Execute ("ALTER tblCCOccurrences ADD COLUMN Year1 Text;"). This gives me; Syntax...
4
by: JenavaS | last post by:
I am trying to create a macro to change a data type in a column. The table was created using a "make-table" query, and the column(s) I want to modify were created using a calculation in my query. ...
8
by: OfficeDummy | last post by:
Hi everyone, I'm running SQL statement in my VBA code (importing an Excel file), but there seems to be a syntax mistake. I've googled and yahooed the Internet, but found nothing that applies to my...
6
by: patriciashoe | last post by:
I have been struggling with this update statement. At this point I get a syntax error if i go from SQL view to design view. Can anyone spot a problem? UPDATE teacherresources AS A SET...
1
by: samneil | last post by:
I have 1 Database( MS Access) with 9 tables and 6 queries, Now I'm trying to view my 2 different tables on my VB6.0 using 2 Datagrids and 2"adodc".... here are the names of my two tables:...
3
by: shalskedar | last post by:
In my Db i need to update 3 columns..Below is my code to update but giving me an error...Can anyone Plz help me with this... str = "update set .='" & UserForm1.TextBox2.Text &...
8
by: Lars131 | last post by:
I'm working on a simple form to database program but I keep encountering a syntax error with my SQL statement. Since it's so long, I don't want to parameterize it, but I will if it's the only...
0
by: Daniel Halvorse | last post by:
hi I am working on an application that manages the data in a access database. but i cant seem to get past this error. When i try to run it it says: "Syntax error in INSERT INTO statement" syntax...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
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...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...
0
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...

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.