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.

Error running DoCmd.RunSQL

101 100+
I am trying to capture a users login ID when entering the dbase and write the ID and NOW() to a log file. My code is as follows:-

Expand|Select|Wrap|Line Numbers
  1.  NewDate = Now()
  2.         uDate = NewDate
  3.         ID = Me!cboEmployee
  4.        MsgBox (NewDate & NewName & uDate)(This Shows correct Detail)
  5.  
  6.         strSQL = "INSERT INTO tbleUserLog (ID,uDate)"
  7.  
  8.         DoCmd.RunSQL (strSQL) 
I get a runtime errors on the DoCmd statement as follows

Runntime Error 3134 Syntax Errorn in INSERT INTO Statement.

I am quite new to access so my question is probably quite stupid but could someone please advise.
Oct 21 '11 #1

✓ answered by jimatqsi

Should be something like this:

Expand|Select|Wrap|Line Numbers
  1. INSERT INTO tbleUserLog ( UserID, uDate )SELECT Now() AS Udate, ID AS UserID
Jim

17 4091
jimatqsi
1,271 Expert 1GB
Should be something like this:

Expand|Select|Wrap|Line Numbers
  1. INSERT INTO tbleUserLog ( UserID, uDate )SELECT Now() AS Udate, ID AS UserID
Jim
Oct 21 '11 #2
Cyd44
101 100+
Thank you Jimatqsi, the satement runs but I then get a systems parameter box and it is look for me to give the required ID and Date

Does not appear to pass the values in the INSERT statement
Oct 21 '11 #3
NeoPa
32,556 Expert Mod 16PB
Let's start with How to Debug SQL String and When Posting (VBA or SQL) Code. We can continue when you've posted your SQL string for the question.
Oct 21 '11 #4
NeoPa
32,556 Expert Mod 16PB
I just looked at the code again and you needn't worry about posting the SQL. There are no variables in it to make it anything other than the string included on your line #6. I can happily work with that (It's still an important point to remember generally for working with SQL but we needn't worry overly here).

Your SQL string is half missing. You've told it where to enter the data, but have not supplied any data to enter. There are two alternative ways to supply data to such a query, one is in a value list and the other is in a recordset (FROM clause).

There are also two ways of learning more about this. One is by using the Help system (See Finding Jet SQL Help.) and the other is to use the Query Designer to create such a query for you and see what the resultant SQL is.

PS. That's not right again. Your code is a little bizarre so I misread it again. It appears you are trying to pass values and haven't specified the fields to copy the data to (although the syntax used is the one for specifying that). The same advice will sort you out though. Check either help or an Access created query to see how it should be done. In this case you are looking for the VALUES alternative.

Let us know how you get on with it. I'm sure we can help more if you get stuck but you shouldn't from there.
Oct 21 '11 #5
Cyd44
101 100+
Hi Again,

Jimatqsi had also spotted that and gave me a better syntax which works but it info does not appear to have been passed to INSERT.
Oct 21 '11 #6
jimatqsi
1,271 Expert 1GB
Cyd44, the problem is most likely that the column names in the table tbleUserLog are not 'ID' and 'uDate'. I made that assumption from looking at the small piece of code you posted.

You have to know what your table structure looks like in order to properly form the SQL to operate on the table. Make the appropriate name changes to the SQL I gave you, based on your table structure.

As an example, this code is adding a row to the table Users. The column names of that table are "UserID" and "UserEmail "

Expand|Select|Wrap|Line Numbers
  1. INSERT INTO Users ( UserID, UserEmail ) SELECT "Jim" AS UserID, "jim@mydomain.com" AS UserEmail;
I have hard-coded the data; your data will come from your form and from the Date function.

Jim
Oct 21 '11 #7
NeoPa
32,556 Expert Mod 16PB
Cyd44:
Jimatqsi had also spotted that and gave me a better syntax which works but it info does not appear to have been passed to INSERT.
So at this point you tell us what you tried and what (exactly) happened. The Error Message would be useful and any noticed results (IE. No records added).
Oct 21 '11 #8
Cyd44
101 100+
Hi Jjimasqi

Here is my amended code
Expand|Select|Wrap|Line Numbers
  1.  Dim strSQL As String
  2.         newID = Me!cboEmployee
  3.         MsgBox (newID)
  4.  
  5.         strSQL = "INSERT INTO tbluserLog ( ID, uDate )SELECT DATE() AS Udate, newID AS ID"
  6.  
  7.  
  8.  
  9.         DoCmd.RunSQL (strSQL)
  10.         MsgBox ("Info" & " " & ID & Date)
The code runs but it is still asking me for a parameter. I have checked back at the log file and we only have 2 fields
1 is the ID field (key field - Autonumber)
2 is uDate Date/Time Short Date

For some reasom the the strSQL is not assigning the Variables
Oct 21 '11 #9
NeoPa
32,556 Expert Mod 16PB
You have the fields the wrong way around I'm afraid.

Try either :
Expand|Select|Wrap|Line Numbers
  1. strSQL = "INSERT INTO tbluserLog ( [ID], [uDate] ) SELECT " & newID & ", DATE()"
or :
Expand|Select|Wrap|Line Numbers
  1. strSQL = "INSERT INTO tbluserLog ( [ID], [uDate] ) VALUES (" & newID & ", DATE())"
Both should be valid. The latter format is provided specifically for entering literal values whereas the former is mainly for transferring data from one table into another (though can be used, in exactly the way Jim does, to handle literal values for a single record too).
Oct 21 '11 #10
Cyd44
101 100+
Have been trying different things and my code is now
Expand|Select|Wrap|Line Numbers
  1. MsgBox (Me!cboEmployee)
  2.  
  3.         newdate = Now()
  4.         udate = newdate
  5.         newID = Me!cboEmployee
  6.         MsgBox (newdate & newID & udate)
  7.  
  8.         strSQL = "INSERT INTO tbleUserLog ( ID, uDate )SELECT Now() AS Udate, newID AS ID"
  9.  
  10.  
  11.  
  12.         DoCmd.RunSQL (strSQL)
  13.  
It works with no Syntax errors and the MsgBox Command shows the corect info. However, I still get a parameter box. When I enter the datils required I get an Error "Cant find tbluserLog?
Oct 21 '11 #11
jimatqsi
1,271 Expert 1GB
Is there a typo in your code for the name of the table? "Can't find tblusreLog" means exactly that.

In your code I see this
tbleUserLog
and in your report of the error I see this
tbluserLog

Jim
Oct 21 '11 #12
NeoPa
32,556 Expert Mod 16PB
Good spot Jim.

Going by the code and results reported in posts #9 & #11 I would deduce that the table is actually called [tblUserLog] (or case variations of that) and not [tbleuserLog] as originally posted.

This makes sense too, as error messages typically need to be copied manually, so if you don't notice the difference you're likely to type what you think you see. One of the main reasons why it is so important to use Copy / Paste wherever possible. Not possible for an error message though unfortunately. An unavoidable oversight in the circumstances.
Oct 21 '11 #13
Cyd44
101 100+
Thanks guys, I had spotted same and am not getting that any more.

Here is the scenario with current coding as follows:-

Expand|Select|Wrap|Line Numbers
  1. strSQL = "INSERT INTO tbluserLog ( ID, uDate )SELECT Now() AS Udate, newID AS ID"
ID is a Long and is defined in a Module because I want to retrieve it before a user logs off.
uDate is DATE/TIME now set as General (guess this is what NOW() requires?)
Logon consist on a Combo Box for Name and an unbound Password Box

-- SNIP --
Oct 21 '11 #14
NeoPa
32,556 Expert Mod 16PB
@Cyd44
In case you overlooked the edit comment let me say that you need to post any new questions in separate threads.

Now this one is completed may I suggest that post #2 would make a good Best Answer for this thread?
Oct 21 '11 #15
Cyd44
101 100+
Point Taken, I am new to this Forum and assumed I was still trying to resolve original problem.

Anyway, I have just realised that I can utilese the Module info anyway when a booking is made so I dont need to use a table to capture what I want.
Thanks agian to both of you. Have chosen best answer based upon your recomendation.
Oct 21 '11 #16
NeoPa
32,556 Expert Mod 16PB
Cyd44:
Point Taken, I am new to this Forum and assumed I was still trying to resolve original problem.
Of course you are, and my task as a moderator is to help and instruct on forum usage as well as the more technical aspects. We all make small mistakes when things are new and we learn. No problem.

In this case, what is a single item (or project) for you, doesn't necessarily fall into the same technical question on a forum. Your questions are a useful resource for other people who need similar help. We aim to keep it that way so we have rules to keep the threads on different topics. That way they are the most use to everyone involved.

On the plus side, there's no specified limit to the number of threads you can initiate. We'll take whatever you can throw at us ;-)
Oct 21 '11 #17
jimatqsi
1,271 Expert 1GB
Thanks for your guiding hand, Ade.
Oct 22 '11 #18

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

Similar topics

0
by: Jim | last post by:
I am using Access 97 on a PC running Windows NT 4.0 SP6a. I have some code (shown below) intended to add a set of records to one table (tblGradeProps) when a new record is created in another...
4
by: Rotsj | last post by:
Hi, i try to execute an update query from within a form, but i get the message: run time error '3144'. Syntax error on the update statement when i try something like this: DoCmd.RunSQL...
0
by: Andy | last post by:
Hello, I am running an sql statement that INSERTS INTO a table. If I run the query using docmd.runSQL, it works fine - new records are added to the table and duplicate records are disregared (...
3
by: Pathfinder | last post by:
Hi All I am trying to run the below but I receive the following error "runsql action requires an argument consisting of an SQL statment" Dim MySQL$ MySQL$ = "Select * from mytablename"...
7
by: Richard Hollenbeck | last post by:
Help! I don't know why this isn't working: Private Sub Combo9_Change() Dim UsersCourseSelection As String UsersCourseSelection = Me("Combo9").Value Combo13.Visible = True 'the following...
8
by: RC | last post by:
In my Access 2002 form, I have a combo box and on the AfterUpdate event I use DoCmd.RunSQL ("UPDATE .... to update records in a table. When it starts to run I get a message "You are about to...
6
by: David | last post by:
I am trying to insert an employee number into the EmpNbr field in my main table from a form where I add a new employee to my employee table. I was hoping this command would work, but it isn't. ...
2
by: ben | last post by:
I have the following code in a VBA module: DoCmd.RunSql "Update tData Set sd = Log(Strike/Price) where symbol = '" & symbol & "'" This statement worked fine, and was using the built in math...
3
by: jl2886 | last post by:
Hello. I have two questions: Private Sub Form_Load() Dim assID As Long assID = DMax("CLng(Right(,3))", "Master_Log") Me.LSI_Case_Number = Month(Date) & Format(Year(Date), "yy") & "-" &...
4
TheSmileyCoder
by: TheSmileyCoder | last post by:
I have been playing around with transactions and one thing got me wondering. First is the code I am using: 'Start transaction 'Get default Workspace. Dim wrkDefault As...
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...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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.