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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Insert Value from Previous Record

Status
Not open for further replies.

JRWPD

Technical User
Nov 28, 2003
13
US
To Insert a value into a field from a Previous Record we can use CTRL + Apostrophe (') .
I have a form with fifteen or so fields on it. I want to be able to fill in the form using the values from the previous record using eight or so fields, but not all of the fields from the previous form on a selective basis. Maybe by the use of a command button and how would that be done.
Any suggestions would be greatly appreciated.
Thanks.
JR
 
JR,

You can try this.

sub addnewdata()

dim cdb as database
dim rec as recordset
dim fld1, fld2, fld3, fld4, fld5, fld6, fld7, fld8, strsql, strsql2 as string

set cdb = currentdb()
set rec = cdb.openrecordset("table or qry name")

rec.movelast
fld1 = rec.("Field1").value & ", "
fld2 = rec.("Field2").value & ", "
fld3 = rec.("Field3").value & ", "
fld4 = rec.("Field4").value & ", "
fld5 = rec.("Field5").value & ", "
fld6 = rec.("Field6").value & ", "
fld7 = rec.("Field7").value & ", "
fld8 = rec.("Field8").value

strsql1 = "INSERT INTO tablename(field1,field2,etc) VALUE("
strsql2 = fld1 & fld2 & fld3 & fld4 & fld5 & fld6 & fld7 & fld8 & ")"

docmd.runsql strsql1 & strsql2
docmd.requery

end sub

Basically what I did was open up the recordset and took the values of the last record and saved it.

The sql lines adds a new record with the saved values. Then refreshes the picture so that you can see the update.

Hope this works. If not let me know.

Ken
 
Sorry I noticed a typo on one of my declared variable.

where it says dim fld1,......fld8, strsql....

place a 1 at the end of strsql so that its strsql1

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top