473,414 Members | 1,563 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,414 software developers and data experts.

SQL Syntax Error

Run-time errpr '3134':
Sytanx error in INSERT INTO statement.

I don't see what I am doing wrong. Thank you for helping in advance.

Expand|Select|Wrap|Line Numbers
  1. lblUsername.Caption = fOSUserName
  2.  
  3. strTable = "tblUserLog"
  4. strColumns = "(Username, Time)"
  5. strValues = "('" & lblUsername.Caption & "', '" & Time() & "')"
  6.  
  7. strSQL = "INSERT INTO " & strTable & " " & strColumns & " VALUES " & strValues & ";"
  8.  
  9. DoCmd.RunSQL strSQL
  10.  
Sep 29 '10 #1

✓ answered by Mariostg

Looks like you lost the single quotes surrounding the Time() function and your label caption.
You should have
Expand|Select|Wrap|Line Numbers
  1. strSQL = "INSERT INTO tblUserLog (Username,Time1) VALUES ('" & lblUsername.Caption & "','" & Time() & "')" 
  2.  

7 1347
Try this ...

strSQL = "INSERT INTO tblUserLog (Username,Time) VALUES ('" & lblUsername.Caption & "'," & Time() & ")"

The messy stuff about single and double quotes and strings inside sql strings is a source of huge confusion to me, too! I think making more substrings has made your Insert statement even more difficult to unravel.
Sep 29 '10 #2
Mariostg
332 100+
Time is a reserved word in access. It is a function. So if you use it as a field Name, you must enclose it between square brackets. [Time]
It would be much safer to use a different name to avoid confusion. LogTime... maybe.
Sep 29 '10 #3
Juilet,
That didn't work either. There are 3 columns in the table: UserID, Username, Time. Does that change anything?
Sep 29 '10 #4
I changed Time to Time1 and now I am getting:

Syntax error (missing operator) in query expression '1:31:20 PM'.


Expand|Select|Wrap|Line Numbers
  1. strSQL = "INSERT INTO tblUserLog (Username,Time1) VALUES (" & lblUsername.Caption & "," & Time() & ")"
  2.  
  3. DoCmd.RunSQL strSQL
  4.  
Sep 29 '10 #5
Mariostg
332 100+
Looks like you lost the single quotes surrounding the Time() function and your label caption.
You should have
Expand|Select|Wrap|Line Numbers
  1. strSQL = "INSERT INTO tblUserLog (Username,Time1) VALUES ('" & lblUsername.Caption & "','" & Time() & "')" 
  2.  
Sep 29 '10 #6
The number of fields won't make any difference as long as the bit in brackets ... (Username,Time1) ... has the same number of fields in the same order as the stuff in the VALUES brackets, (and of course UserName and Time1 must be names of fields in the table)

If Time() is a date/time function you could try

strSQL = "INSERT INTO tblUserLog (Username,Time1) VALUES ('" & lblUsername.Caption & "',#" & Time() & "#)"

It's getting late and I'm well into my bottle of wine: I'll look in the morning and definitely sort this one out if someone else hasn't overnight.

Good luck!
Sep 29 '10 #7
Oralloy
988 Expert 512MB
You might try:
Expand|Select|Wrap|Line Numbers
  1.   Dim strSQL$
  2.   strSQL = "INSERT " & vbCrLf & _
  3.            "  INTO tblUserLog (Username,Time1)" & vbCrLf & _
  4.            "  VALUES('" & lblUsername.Caption & "', " & _
  5.                      "#" & CDate(Time()) & "#)"
  6.  
  7. DoCmd.RunSQL strSQL
  8.  
Sep 29 '10 #8

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

Similar topics

7
by: Yesurbius | last post by:
I am receiving the following error when attempting to run my query. In my mind - this error should not be happening - its a straight-forward query with a subquery. I am using Access 2003 with all...
5
by: rolltide | last post by:
I've seen many similar threads, but despite repeated efforts I cannot figure out my problem. I am running Access 2003, VB 6.5, Office XP Pro. Code excerpt is below (you can see where I've tried...
2
by: GLEberts | last post by:
I can not seem to get rid of this syntax error - hope someone can help out. the error I am getting is: Run time Error 3075 Syntax error missing operator in query expression =name I have...
11
guillermobytes
by: guillermobytes | last post by:
Hi, i'm making a query with PDO and there is a SQL syntax error in it. $sql = 'BAD CODE'; $pdoStmt = $pdo->prepare($sql); if (false === $pdoStmt) { echo 'ERROR'; }
2
by: erone | last post by:
Hello, good morning. I have a syntax error here. Can you help? Thanks. It's a Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' on the "echo" line : <? $sql = "SELECT addrid,...
1
by: Bauklotz | last post by:
So, recently I've been experimenting with a telnet server, and a 5250 terminal emutator and I thought of making a field system, for easier graphical (well, not quite) displaying. This basically...
3
by: brkseven | last post by:
Looking for help with this Contact Form. The error is on line 1, but that' doesn't mean a lot, I think. In fact, a php syntax check passed it, but I was hoping for an easy syntax error, it looks...
13
Topbidder
by: Topbidder | last post by:
I have this error on the code Parse error: syntax error, unexpected '"' in /home/topbidd/public_html/bid2/bid_classic.php on line 159 now i thought the error was this It seems that the...
3
by: CYNTHIA CUTRER | last post by:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> ...
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?
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
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,...
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.