Solved

Update query based on number of digits

Posted on 2013-11-23
6
271 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
  • 4
6 Comments
 
LVL 84

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
LVL 61

Expert Comment

by:mbizup
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
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…

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now