Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Update Query with MAX(Date) from another table

Status
Not open for further replies.

Swi

Programmer
Feb 4, 2002
1,966
US
I have the following query I am trying to perform:

Code:
conn.Execute "UPDATE Master SET Master.Scan_Date = (SELECT Max(Scan_Date) From IMB_Tracing INNER JOIN IMB_Tracing.IMB_Tracking_Code = Master.IM_Barcode_Digits);"

I get the error "Operation must use an updateable query".

Any ideas on how I can resolve this?

Thanks.

Swi
 
What about this ?
Code:
conn.Execute "UPDATE Master M" _
 & " INNER JOIN (SELECT IMB_Tracking_Code,MAX(Scan_date) AS LastDate FROM IMB_Tracing GROUP BY IMB_Tracking_Code) I" _
 & " ON M.IM_Barcode_Digits=I.IMB_Tracking_Code" _
 & " SET M.Scan_Date=I.LastDate"
or this ?
Code:
conn.Execute "UPDATE Master" _
 & " SET Scan_Date=DMax(""Scan_Date"",""IMB_Tracing"",""IMB_Tracking_Code='"" & IM_Barcode_Digits & ""'"")"
If IM_Barcode_Digits and IMB_Tracking_Code are numeric then get rid of the single quotes.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
On the first bit of code I get the same error as my code above.

On the second bit of code I get the following error:

"Undefined function 'DMax' in expression.

Thank you for the help.

Swi
 
And this ?
Code:
conn.Execute "UPDATE Master" _
 & " SET Scan_Date=(SELECT Max(Scan_Date) FROM IMB_Tracing WHERE IMB_Tracking_Code=IM_Barcode_Digits)"

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
I also get the error "Operation must use an updateable query".

Swi
 
Do you get the Date you want if you run:

[tt]SELECT Max(Scan_Date)
From IMB_Tracing INNER JOIN
IMB_Tracing.IMB_Tracking_Code = Master.IM_Barcode_Digits[/tt]

I assume [tt]Master.Scan_Date [/tt]is declared as Date

Can you run this without an error:

[tt]UPDATE Master SET Master.Scan_Date = #3/21/2014#[/tt]

Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.
 
I get a syntax error in the from clause of your first select

Yes, they are declared as dates.

Yes, it will update the table just fine with your last statement.

Thanks.

Swi
 
My last attempt.
Create a query named, say, qryGetLastDate:
SQL:
SELECT IMB_Tracking_Code,MAX(Scan_date) AS LastDate FROM IMB_Tracing GROUP BY IMB_Tracking_Code
Then, try this:
Code:
conn.Execute "UPDATE Master M INNER JOIN qryGetLastDate I" _
 & " ON M.IM_Barcode_Digits=I.IMB_Tracking_Code" _
 & " SET M.Scan_Date=I.LastDate"

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
My first Select statement was taken from your original post, it is your Select. :)
So first thing I would do is make sure my inner-select statement returns what I want - the Max Date

Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.
 
Thanks for the attempts to help. PHV, thanks but I get the updateable error yet again.

Andrzejek, using PHV's code I get the max date but on the connection execute code I receive the error.

I am updating the database in other areas in my app as well with no issue. This is driving me nuts.



Swi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top