Using MAX from another table in a INSERT action.

  • Thread starter Thread starter Fernando Morais
  • Start date Start date
F

Fernando Morais

Hi,

i was trying to do a query that is inserting values on a DB, and one of
the field should be the result from a query using MAX on antoher DB.
Something like this:

INSERT INTO tblSNew ( idEquipamento, idCliente, idSWDescrição )
VALUES ((SELECT MAX(idEquip) FROM tblHW), (Forms!frmAddPC!txtCli),
(Forms!frmAddPC!txtPC));

But this gives and undefined error in access, i've tried changing the
(SELECT MAX(idEquip) FROM tblHW) to (MAX(tblHW.idEquip)) and it says i
can't use aggregated functions.

And i'm stuck here, is it any mistake on that? Is that possible, or i
need to do it in another way?

Thanks.
 
You might be able to use

INSERT INTO tblSNew ( idEquipamento, idCliente, idSWDescrição )
SELECT Max(IdEquip)
, Forms!frmAddPC!txtCli
, Forms!frmAddPC!txtPC
FROM tblHW
GROUP BY Forms!frmAddPC!txtCli
, Forms!frmAddPC!txtPC

Or use the DMax function as posted elsewhere.
 
Thank you,

I'm going to try that, i've used DMAX and it worked.
But i'm going to try this one too.

In the mean time, until i had no answer i went for a longer route.
Using SELECT INTO, creating a temp table and then moving the data to the
correct table using a INSERT.
 

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

Back
Top