Update Max value to another table

Joined
Jan 3, 2009
Messages
2
Reaction score
0
I have a problem with to update with max value to another table..

I have 2 tables :

table A
- IDrpt (Auto Increment)
- pname
- qname

table B
- pID (Auto Increment)
- rptID
- itemno

quest:
I want, if someone fill table B (using form) the rptID on table B automatically update from IDrpt table A with Maximum value of IDrpt table A... so after input value on table B looks like this :

pID rptID itemno
1 9 cake 01
2 9 cake 02
3 9 cake 03

I have tried to write on SQL like this :
UPDATE tblB SET tblB.rptID = "(SELECT Max(tblA.IDrpt) FROM tblA)"
WHERE (((tblB.pID)=(SELECT (Max(pID)) AS PID FROM tblB)));

but not work, but if i wrote like this :
UPDATE tblB SET tblB.rptID = "9"
WHERE (((tblB.pID)=(SELECT (Max(pID)) AS PID FROM tblB)));

it's work... what wrong with my first SQL script?

nb: SQL script wrote as macro and run After Insert


rgds,

tedie
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top