473,480 Members | 2,325 Online
Bytes | Software Development & Data Engineering Community
Create 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 1512
NeoPa
32,556 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.newPsswd" and "WHERE". "Me.newPsswrd" 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.strEmpPassword]" 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,556 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
6210
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: ...
8
11574
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...
2
2500
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...
6
19154
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)...
1
3073
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...
6
2676
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 ...
19
8338
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...
5
3443
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 =...
10
7533
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 =...
4
3043
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...
0
7051
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
6915
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
7097
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...
1
6750
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
6993
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
4493
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...
0
2993
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
567
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
193
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.