473,386 Members | 2,050 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,386 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 1084
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: 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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.