A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Running & Setting Up Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Update query trouble



 
 
Thread Tools Display Modes
  #1  
Old October 16th, 2008, 12:47 AM posted to microsoft.public.access.queries
bhammer
external usenet poster
 
Posts: 54
Default Update query trouble

I want to copy the CodeID value from one record to another, in the same
table, to a certain record where a part of the Doc_Number (for the record
with the CodeID) is found in the Comment field (for the record with a blank
CodeID).

Table Example:
ID CodeID Doc_Number Comment
23 16 DCS01234.jpg Yada, yada, yada.
55 0 DCS09876.jpg Blah, blah, blah. 1234.

The result should copy the 16 from record 23 into the CodeID field for
record 55. This is because the "1234" four-digit string before the file
extension was found somewhere in the Comment field of the other record.

Here's what I have tried so far:
UPDATE tblObservations SET tblObservations.CodeID = "CodeID"
WHERE (((tblObservations.Comments) Like Left(Right("Doc_Number",8),4)));

I'm on the wrong track . . .

  #2  
Old October 16th, 2008, 05:09 AM posted to microsoft.public.access.queries
John W. Vinson
external usenet poster
 
Posts: 18,261
Default Update query trouble

On Wed, 15 Oct 2008 16:47:00 -0700, bhammer
wrote:

I want to copy the CodeID value from one record to another, in the same
table, to a certain record where a part of the Doc_Number (for the record
with the CodeID) is found in the Comment field (for the record with a blank
CodeID).

Table Example:
ID CodeID Doc_Number Comment
23 16 DCS01234.jpg Yada, yada, yada.
55 0 DCS09876.jpg Blah, blah, blah. 1234.

The result should copy the 16 from record 23 into the CodeID field for
record 55. This is because the "1234" four-digit string before the file
extension was found somewhere in the Comment field of the other record.

Here's what I have tried so far:
UPDATE tblObservations SET tblObservations.CodeID = "CodeID"
WHERE (((tblObservations.Comments) Like Left(Right("Doc_Number",8),4)));

I'm on the wrong track . . .


What if several records have a match?

You could try

UPDATE yourtable AS X
SET X.CodeID =
(SELECT CodeID FROM yourtable AS Y
WHERE Y.Comment LIKE "*" & Mid(X.DocNo, 5, 4) & "*")

but I rather doubt it will be an updateable query because of the multiple
matches issue; you may be able to use

UPDATE yourtable SET codeID =
DLookUp("[CodeID]", "yourtable", "Comment LIKE *" & Mid(DocNo, 5, 4) & "*")

to get just the first matching comment.

--

John W. Vinson [MVP]
 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 06:14 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.