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

error in UPDATE statement

65 64KB
I have spent nearly a day and I am really not able to find my mistake..

this Forum has always the best answers so I am hoping someone can Point out what I am doing wrong!!!

it is a simple UPDATE Statement..

Expand|Select|Wrap|Line Numbers
  1. strSQL = " UPDATE " & Me.Combo81 & _
  2.          " SET " & "[" & Me.Combo81 & "]" & "." & "[" & Me.Combo79 & "]" & " = tbl_Import.[" & Me.Combo83 & "]" & _
  3.          " WHERE [tbl_Import].[pnr] = " & Me.Combo81 & ".[pnr];"
as you can see the Target Table and the field are from Combo boxes. also the field of the tbl_Import.

the SQL on printing gives the perfect one that i want it to be...

Expand|Select|Wrap|Line Numbers
  1. UPDATE MLE_Table SET [MLE_Table].[NHA] = tbl_Import.[Prio] WHERE [tbl_Import].[pnr] = MLE_Table.[pnr];
but the Problem is that the code does not recognise the values tbl_Import.[pnr] and tbl_Import.[Prio].
"Enter parameter" box Pops up everytime.

please tell me if anyone can see what i am doing wrong.
Feb 24 '16 #1

✓ answered by NeoPa

Hi Saran.

The problem with the SQL is that you're trying to refer to a table (tbl_Import) that hasn't been included in the tables involved.

In your UPDATE clause you need to include all tables and queries that you intend to use in your query. This is similar to the FROM clause in a SELECT query.

BTW. Well done for including the SQL. The VBA was largely irrelevant as it's the SQL that isn't working, but you included the SQL as well so we had all we needed to look at your problem.

5 976
NeoPa
32,556 Expert Mod 16PB
Hi Saran.

The problem with the SQL is that you're trying to refer to a table (tbl_Import) that hasn't been included in the tables involved.

In your UPDATE clause you need to include all tables and queries that you intend to use in your query. This is similar to the FROM clause in a SELECT query.

BTW. Well done for including the SQL. The VBA was largely irrelevant as it's the SQL that isn't working, but you included the SQL as well so we had all we needed to look at your problem.
Feb 24 '16 #2
Seth Schrock
2,965 Expert 2GB
SQL can't just grab a value from a table like that. You have to execute a SELECT statement to get the values. You could instead use a DLookup. Also, in your WHERE clause you have a problem because the WHERE clause isn't telling it which records to pull from for your SET value, it is specifying which records get changed. In your SET statement, you don't need the table name repeated as it gets that from the table in the UPDATE statement.

You have a couple of options since you are building this query in VBA. You could use VBA to get the value from Combo83 and just plug that value into your SQL string, or you can put that retrieval in the SQL statement. I would probably do the former myself, but that is up to you.
Feb 24 '16 #3
NeoPa
32,556 Expert Mod 16PB
A useful tip when learning to work with SQL directly is to design an example query using the designer, then see what SQL it creates for you. In case you don't know, there's a SQL view for queries in Access that shows the SQL it uses for your QueryDef object.

This doesn't have to be as flexible as that created by your code. A simple example of one particular instance will give you the SQL that you're aiming to replicate in code in a more flexible way.
Feb 24 '16 #4
saranmc
65 64KB
aahhhh!!!! thank you NeoPa.....

it works.. i should have asked you earlier!! wasted so Long in trying to correct the code when the mistake was in the SQL.

great thank you!!

thanks Seth, DLookup is something i have not done before.. Maybe I will try it next time..
Feb 24 '16 #5
NeoPa
32,556 Expert Mod 16PB
SaranMC:
it works.. i should have asked you earlier!! wasted so Long in trying to correct the code when the mistake was in the SQL.
Such time is rarely wasted time. You'll have learnt from that effort, undoubtedly.
SaranMC:
DLookup is something i have not done before.. Maybe I will try it next time..
I strongly advise against that in a scenario like this. It can be horribly inefficient and is never as clean as including the table inside your SQL. If that's not possible for reasons I can't imagine at this point, then it would be worth considering.

Please remember though, our experts will try to do what they can to help. None of us is all-seeing though, and I can absolutely include myself in that category. We offer the best we know at the time. When Seth posted his advice he hadn't seen my first post. It would probably have got you working, but possibly not in the best way.

Nevertheless, all attempts to help are very much appreciated.
Feb 24 '16 #6

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

Similar topics

3
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: ...
5
by: Wing | last post by:
Hi all, I am writing a function that can change the value "Quantity" in the selected row of MS SQL table "shoppingCart", my code is showing below ...
1
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
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
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...
2
by: travhale | last post by:
in a new project using .net 2005, c#. getting err message "Update requires a valid UpdateCommand when passed DataRow collection with modified rows." source RDBMS is oracle 8i. I add a new...
8
by: Stephen Plotnick | last post by:
I have three forms and update one table in an Access DB with sucess in one form. In the other two forms I'm trying to do an update to a different table in the Access DB. The error I'm getting...
10
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 =...
1
by: David Hogston | last post by:
Having a bad time figuring out what is wrong with my update statement. Been a couple of years since I wrote any scripts. Can anybody tell me what I am doing wrong? Select Statement work fine. ...
4
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
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
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
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...

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.