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

How to solve this syntax error?

I wrote a code that will populate a table in access with data from a text file. Basically, the table has 2 fields: ID and Field1.

ID (number) contains the line number of the text.
Field1 (memo) contains the entire line of text.

This is the code that I am using to populate the table:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command0_Click()
  2.     Dim LineCount As Integer
  3.     Dim Line As String
  4.     Dim strSQL As String
  5.  
  6.     Open "C:\Users\shawnntan\Downloads\oct\Oct2.txt" For Input As #1
  7.  
  8.     While Not EOF(1)
  9.         LineCount = LineCount + 1
  10.         Line Input #1, Line
  11.         strSQL = "INSERT INTO Table2(ID, Field1) VALUES ('" & LineCount & "', '" & Line & "');"
  12.         DoCmd.SetWarnings False
  13.         DoCmd.RunSQL strSQL
  14.         DoCmd.SetWarnings True
  15.     Wend
  16.  
  17.     Close #1
  18. End Sub
  19.  
My code works fine for the first 16 lines of text, but once it reached line 17, I receive a "Runtime Error 3075: Syntax error (Missing operator) in query expression."

The text that is contained in line 17 is
Expand|Select|Wrap|Line Numbers
  1. CRT_ulSSO_CBGSSO_AUTH_HK[(Log_Path="/app/CA/tempfolder/cbgsso/log/" AND Log_Name="auth_HK.log" AND STRSCAN(Description_U, N"AuthTimeout Error initializing DSSS") = 1 ) OR ( STRSCAN=1 OR STRSCAN(Description_U, N"AuthTimeoutException") = 1 ) OR ( STRSCAN=1 OR STRSCAN(Description_U, N"Error initializing DSSS") = 1 ) OR ( STRSCAN=1 OR STRSCAN(Description_U, N"MQException") = 1 ) OR ( STRSCAN=1 OR STRSCAN(Description_U, N"NoServerException") = 1 ) OR ( STRSCAN=1 OR STRSCAN(Description_U, N"System exception error") = 1 ) ) ) ;ULLOGEN=1 ) ON x01gssoapp1a:KUL (Log_Path=/app/CA/tempfolder/cbgsso/log/ Log_Name=auth_HK.log Description_U=28 Oct 14 13:37:54, 868 ERROR [Thread-6687412]: (GCGUtil: getTokenInfo, AGENT ID: ibr_ibapp1a, TransRef: 10000000000506603349) [GCG] Exception:com.ibm.mq.MQException: MQJE001: Completion Code '2', Reason '2033'.: )]~
I can't seem to identify what's wrong with it, can somebody please assist me in rectifying this? :(

PS, I'm unable to change anything from the text file as it is a log file generated by a system.
Nov 19 '14 #1
3 1085
twinnyfo
3,653 Expert Mod 2GB
Shawn,

It is very likely that your memo field has some special characters (such as parentheses, slashes, quotes, etc.) that the VBA does not like, because of the text string created in your code. One possible way to work around this might be to use a recordset for your table instead of an INSERT string.
Nov 19 '14 #2
Rabbit
12,516 Expert Mod 8TB
You have single quotes in that string. You need to either escape them or use a parameterized query.
Nov 19 '14 #3
jforbes
1,107 Expert 1GB
This a cheap and easy way to Escape the single quote so that you can insert the Data:
Expand|Select|Wrap|Line Numbers
  1. strSQL = "INSERT INTO Table2(ID, Field1) VALUES ('" & LineCount & "', '" & Replace(Line, "'", "''")& "');"
  2.  
an alternative is to remove the single quotes all together. This isn't something you should do all the time, but with your data being a logfile, you could probably get away with it:
Expand|Select|Wrap|Line Numbers
  1. strSQL = "INSERT INTO Table2(ID, Field1) VALUES ('" & LineCount & "', '" & Replace(Line, "'", "")& "');"
  2.  
Nov 19 '14 #4

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

Similar topics

5
by: NanQuan | last post by:
I'm hoping someone can help me solve this error since I am at a total loss here. Usually I don't bother posting on any forums or groups on the internet and prefer to solve stuff myself but this is...
2
by: Someonekicked | last post by:
this is example of what is going on my program, and the error im getting : when i try to compile the following : #include <iostream> using namespace std; class first { public: first(int...
4
by: Bradley Kite | last post by:
Hi all. I'm trying to diagnose/solve a problem with internet explorer, whereby sometimes the form submits, and other times IE produces an 'invalid syntax' error. First, I have a form, and...
7
by: Josh | last post by:
Hi All, I know this is a novice question that I should be able to solve through searching but I have Googled my fingers off and not found anything that seems to help. I have the following...
1
by: chug | last post by:
I'm not a programmer but it's my job to solve this. Can someone help me with this error message? Microsoft OLE DB Provider for ODBC Drivers error '80040e14' Syntax error (missing operator)...
4
by: nicholas | last post by:
Hi, On this page you can see a dropdown with auto postback: http://www.b2blearning.be/en/planning.aspx When you change the dropdown, the planning dates are populated. But if you do that a few...
1
by: solomon_13000 | last post by:
connection.asp: <% Sub RunQueryString (pSQL,parms) on error resume next Set conn = Server.CreateObject("ADODB.Connection") conn.open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &...
3
by: SilvaZodiac | last post by:
Hi everyone, I'm still rather new to PHP code, and I have a syntax error. I've tried several different solutions, but it won't fix. It seems to suggest that I need a new bracket somewhere in the...
3
by: osman7king | last post by:
I use the EXECUTE statement in a procedure which has 2 parameters, one is to hold the query, and the other for the value used in the query create or replace function delete_from_table1(character...
1
by: anbujeremiah | last post by:
in beautifulsoup.py file, the following error occurs, if not : self.originalEncoding = None ^ SyntaxError: invalid syntax ------ in above code, how to solve the syntax error...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
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.