Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Update query based on number of digits

Posted on 2013-11-23
6
Medium Priority
?
280 Views
Last Modified: 2013-11-23
I would like to make an update query so that it searches for records in the "SIC Code" field that contain 7 numbers and updates the "Update SIC Name" field with the contents of "SIC Name" field.  How is this done?  Thanks.
Sample.accdb
0
Comment
Question by:daisypetals313
[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
  • 4
6 Comments
 
LVL 85

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 1500 total points
ID: 39671822
Would this work:

DoCmd.RunSQL "UPDATE YourTable SET [Update SIC Name]=[SIC Name] WHERE Len([SIC Code]) = 7"

Note that does not check whether "SIC CODE" contains 7 NUMBERS, it just checks whether it contains 7 characters.
0
 

Author Comment

by:daisypetals313
ID: 39671846
I inserted:
DoCmd.RunSQL "UPDATE [Sample] SET [Update with SIC Name]=[SIC Name] WHERE Len([SIC Code]) = 7"

And received error message:
Invaled SQL statement; expected 'DELETE', 'INSERT', 'PROCEDURE', 'SELECT' or 'UPDATE'
0
 

Author Comment

by:daisypetals313
ID: 39671863
This worked for me, but I'm not sure how it's different

UPDATE sample SET sample.[Update with SIC Name] = [sic name]
WHERE (((Len([sic code]))>7));
0
Technology Partners: 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!

 
LVL 61

Expert Comment

by:mbizup
ID: 39671926
Looks like you entered your SQL statement directly in the query builder.

Scott's query is exactly the same thing, valid SQL syntax embedded in VBA, which will run if you test it in a command button click event or similar.
0
 

Author Comment

by:daisypetals313
ID: 39671944
Thanks mbizup for the explanation.  I think the query builder is easier for me personally (still learning :) but good to know there are multiple ways.
0
 

Author Closing Comment

by:daisypetals313
ID: 39671946
Thanks.
0

Featured Post

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!

Question has a verified solution.

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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

618 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