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: - Private Sub Command0_Click()
-
Dim LineCount As Integer
-
Dim Line As String
-
Dim strSQL As String
-
-
Open "C:\Users\shawnntan\Downloads\oct\Oct2.txt" For Input As #1
-
-
While Not EOF(1)
-
LineCount = LineCount + 1
-
Line Input #1, Line
-
strSQL = "INSERT INTO Table2(ID, Field1) VALUES ('" & LineCount & "', '" & Line & "');"
-
DoCmd.SetWarnings False
-
DoCmd.RunSQL strSQL
-
DoCmd.SetWarnings True
-
Wend
-
-
Close #1
-
End Sub
-
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 - 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.
3 1084
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.
You have single quotes in that string. You need to either escape them or use a parameterized query.
This a cheap and easy way to Escape the single quote so that you can insert the Data: - strSQL = "INSERT INTO Table2(ID, Field1) VALUES ('" & LineCount & "', '" & Replace(Line, "'", "''")& "');"
-
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: - strSQL = "INSERT INTO Table2(ID, Field1) VALUES ('" & LineCount & "', '" & Replace(Line, "'", "")& "');"
-
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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)...
|
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...
|
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=" &...
|
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...
|
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...
|
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...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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: 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,...
|
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,...
| |