Solved

updating more than 1 field using sql statement

Posted on 2002-07-20
7
128 Views
Last Modified: 2010-05-02
Here is the code I am now using.  How would I rewrite this to update more than 1 field without writing multiple Update statements?  I have around 30 fields to actually update in my Access Database.
0
Comment
Question by:sjmmajor
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 33

Expert Comment

by:hongjun
ID: 7166766
try this update statement example

update table_name
set field1 = field1_value,
field2 = field2_value
where id = 1


hongjun
0
 
LVL 2

Expert Comment

by:yongyih
ID: 7166848
Syntax
UPDATE [DatabaseName1!]TableName1
SET Column_Name1 = eExpression1
  [, Column_Name2 = eExpression2 ...]
  WHERE FilterCondition1 [AND | OR FilterCondition2 ...]]


Good Luck.
0
 
LVL 2

Expert Comment

by:priya_pbk
ID: 7168000
I think you have forgotton to post your code, anyways hongjun and yongyih are correct for the update statement. How were you doing the same then??

-priya
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:sjmmajor
ID: 7169335
I tried the above and it gives me a parameter error.  Here is my code.

sSql1 = "UPDATE 22shop_5min SET jobnumber= " & JobNumber22 & " where [22shop_5min].id = 1"

If I had fields
text1
text2
text3
how would I go about using those fields in one statement?
0
 
LVL 2

Accepted Solution

by:
priya_pbk earned 50 total points
ID: 7170111
This..

sSql1 = "UPDATE 22shop_5min SET jobnumber= " & JobNumber22 & " where [22shop_5min].id = 1"

would be then..

*
sSql1 = "UPDATE 22shop_5min SET jobnumber= " & Text1 & ",jobname='" & Text2 & "',jobdesc='" & Text3 & "' where [22shop_5min].id = 1"

This is just an example. Basically what you are doing here is dynamically creating a sql-query at runtime. It's simple enough!!

*the jobName and jobdesc are dummy fields just to show how exactly it should be written.

Hope this helps!

-priya
0
 

Author Comment

by:sjmmajor
ID: 7170230
Thanks so much.  It was syntax that was getting me.  I knew it had to be easy.  I just couldn't see it.

Great!!
0
 
LVL 2

Expert Comment

by:priya_pbk
ID: 7170965
you're welcome!
-priya
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Macro: print each sheet to pdf using ExportAsFixedFormat 11 64
Put text in a picture ASP.NET C# 2 68
How does CurrentUser work? 10 42
vb6 connector to mongodb 2 143
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question