Solved

Update query based on number of digits

Posted on 2013-11-23
6
273 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
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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
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.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

861 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

30 Experts available now in Live!

Get 1:1 Help Now