473,545 Members | 2,413 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with an Update statement

101 New Member
I am trying to update a table but keep getting a compile error on the following code:-

Expand|Select|Wrap|Line Numbers
  1. Dim strSQL As String
  2. strSQL = "Update [tblEmployees], Set [tblEmployees.strEmpPassword] = Me.newPsswd" _
  3.          "WHERE strEmpPassword = Me.oldPsswd"
  4.  
  5. DoCmd.RunSQL strSQL
Have looked for syntax rules on web and feel that the above should work but Access Event will not accept it.

Can anyone help.
Oct 24 '11 #1
4 1521
NeoPa
32,564 Recognized Expert Moderator MVP
Cyd, I'm sure I must have posted links before on how to post here. The rules aren't that difficult, but you seem to be struggling with them. See When Posting (VBA or SQL) Code please before posting again. Had you followed the instruction at A2 we wouldn't need to be looking at this (or at least we would have had line number and error message to work with).

The problem is actually with your lines #2 & #3. This is a single line of code due to the continuation character, but the two strings are not added together as (presumably) intended because the ampersand (&) character is missing. It should read :

Expand|Select|Wrap|Line Numbers
  1. Dim strSQL As String
  2. strSQL = "Update [tblEmployees], Set [tblEmployees.strEmpPassword] = Me.newPsswd" & _
  3.          "WHERE strEmpPassword = Me.oldPsswd"
  4.  
  5. DoCmd.RunSQL strSQL
At this point you would have had a SQL failure on line #5 as the comma (,) after "[tblEmployees]" is not correct and there is no space between "Me.newPssw d" and "WHERE". "Me.newPssw rd" is also passed as a literal string within your SQL rather than passing its value and surrounding it in quotes to indicate it's a string value. There's also the matter of "[tblEmployees.st rEmpPassword]" being an invalid field reference. It should probably end up something like :

Expand|Select|Wrap|Line Numbers
  1. Dim strSQL As String
  2.  
  3. strSQL = "UPDATE [tblEmployees] " & _
  4.          "SET    [strEmpPassword] = '" & Me.newPsswd & "' " & _
  5.          "WHERE  ([strEmpPassword] = '" & Me.oldPsswd & "')"
  6. Call DoCmd.RunSQL(strSQL)
NB. Notice though, the separate parts of of the problem in the VBA (on one side) and the SQL (on the other).
Oct 24 '11 #2
Cyd44
101 New Member
NeoPa
Firstly I apologise for the not following rules. I had tried to follow them but made a typo on the [/code] comand and had {/code] instead. As a result it did not format the code. I did try homest but had finger trouble.

In relation to my question, once again you are a star. I had tried following web examples but they all seem to miss out the '" & statements. Many thanks
Oct 24 '11 #3
NeoPa
32,564 Recognized Expert Moderator MVP
I'm very pleased to have helped. The [ CODE ] tags weren't a problem, but see my PM for more on that. You're coming along and I'd be surprised if you didn't go further. It's always hardest to get started.
Oct 25 '11 #4
Cyd44
101 New Member
Thats Very kind of you to say. Without your help I would be totally lost. I have a wierd problem now with the application itself and will post another question in order to keep to the rules
Oct 25 '11 #5

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

Similar topics

3
6216
by: Robert Mark Bram | last post by:
Hi All! I have the following two methods in an asp/jscript page - my problem is that without the update statement there is no error, but with the update statement I get the following error: Error Type: Microsoft OLE DB Provider for ODBC Drivers (0x80004005) Syntax error in UPDATE statement. /polyprint/dataEntry.asp, line 158
8
11585
by: pb648174 | last post by:
I have a single update statement that updates the same column multiple times in the same update statement. Basically i have a column that looks like .1.2.3.4. which are id references that need to be updated when a group of items is copied. I can successfully do this with cursors, but am experimenting with a way to do it with a single update...
2
2507
by: serge | last post by:
/* This is a long post. You can paste the whole message in the SQL Query Analyzer. I have a scenario where there are records with values pointing to wrong records and I need to fix them using an Update statement. I have a sample code to reproduce my problem. To simplify the scenario I am trying to use Order related tables to explain a...
6
19160
by: HeadScratcher | last post by:
I am trying to speed up my update statements by removing inner select statements. Example: update orders set shipname = (select contactName from customers where customerid = orders.customerID) I read some articles which said that I should be able to use an inner join on the update statement like the following:
1
3084
by: amitbadgi | last post by:
HI i am getting the foll error while conv an asp application to asp.net Exception Details: System.Runtime.InteropServices.COMException: Syntax error in UPDATE statement. Source Error: Line 112: MM_editCmd.ActiveConnection = MM_editConnection Line 113: MM_editCmd.CommandText = MM_editQuery Line 114: MM_editCmd.Execute
6
2682
by: FayeC | last post by:
I really need help figuring this out. i have a db with mostly text fields but 2. The user_id field is an autonumber (key) and the user_newsletter is a number (1 and 0) field meaning 1 yes the person wants to receive a newsletter and 0 no, don't want to receive it. Now.....when trying to create an UPDATE statement I am running into problems...
19
8350
by: Steve | last post by:
ASP error number 13 - Type mismatch with SELECT...FOR UPDATE statement I got ASP error number 13 when I use the SELECT...FOR UPDATE statement as below. However, if I use SELECT statement without FOR UPDATE, it is fine and no error. I also tried Set objRs = objConn.Execute("SELECT * FROM EMP UPDATE OF EMPNO"), but it still couldn't help. ...
5
3455
by: Slavan | last post by:
I have an update statement that I'm executing against Oracle database from my C# code and it won't work. UPDATE MenuCaptions SET Caption = N@Caption WHERE MenuId = @MenuId AND CultureId = @CultureId Caption is an nvarchar type. MenuId and CultureId are integers. I get Exception with the following message: ORA-00933: SQL command not...
10
7543
by: Luigi | last post by:
Hello all! I'm a newbie in PHP. I have written a short script that tries to update a SQLite database with the user data. It is pretty simple, something like this: <?php $sqlite = sqlite_open("mytest.db", 0666, $sqlite_error);
4
3049
by: moepusu | last post by:
Hi all I have problem using table variable in update statement. Please see below. mpyemp="febpyemp" && this file name will change everymonth in my update statement DoCmd.RunSQL "update pyemp INNER JOIN {Mpyemp}
0
7487
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7680
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7446
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7778
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6003
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
4966
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3476
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1908
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1033
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.