Pull last data record into a new table
Posted by: Mike F
Date: June 18, 2020 01:59PM

want to thank you all for your help right away.

2 tables, I want to pull the last record from table1 column "ProjName" and input it into table 2 column "ProjName". (I will use this field to as the relationship between the two tables).

When "add record" button on the form is pressed it writes the data to table1 no problem. So right now it is coping the entire column. I need it to just copy the last record (the newest 'Name"). ... there's also a reset button so that the record isn't saved if the user wants.

I currently have the following code to do this in the button click event:

Dim dbs As Database

Set dbs = CurrentDb
dbs.Execute "INSERT INTO tbl_ProjDetails (ProjName) SELECT (ProjName) FROM tbl_Projectsummary;"

I tried using various versions of the DLast function, needless to say it doesn't work (I don't even know if it's able to work within the INSERT INTO):

dbs.Execute "INSERT INTO tbl_ProjDetails (ProjName) SELECT DLast(ProjName) From tbl_Projectsummary);"

I have also tried just pulling from the text box directly:
dbs.Execute "INSERT INTO tbl_ProjDetails (ProjName) VALUES('" & Me.txt_projname & "')"

Any thoughts on how to do this...? I may be trying to do this scenario the wrong way, so feel free to point me in another direction.

End goal - I need to fill out 5 record sets with that name in table2, each with a different department which is another column, but right now I would just be happy getting that last record to pull - as I figure the rest will just be standard INSERT INTO

Options: ReplyQuote


Subject
Written By
Posted
Pull last data record into a new table
June 18, 2020 01:59PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.