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

ignore 2 fields when using copy & paste

Status
Not open for further replies.

Richey

Technical User
Aug 29, 2000
121
GB
I have the following function which copies the data from all the fields and pastes to a new record. However I want 2 fields to be ignored, namely Ref and saref
How can I do this please?

thanks

Function CopyRec()
Dim rstcp As DAO.Recordset
Dim rstnew As DAO.Recordset
Dim fieldnum As Integer

Set rstcp = CurrentDb.OpenRecordset("tblactions", dbOpenSnapshot)
Set rstnew = CurrentDb.OpenRecordset("tblactions", dbOpenDynaset)

rstcp.MoveLast
rstnew.AddNew

For fieldnum = 0 To (rstcp.Fields.Count - 1)
rstnew.Fields(fieldnum).Value = rstcp.Fields(fieldnum).Value
Next fieldnum

rstnew.Update
rstcp.close
rstnew.close

End Function
 
The onloy way I know to do this would be to create your recordsets using SQL rather that using the whole table.

dim strSql as string
dim rst as recordset
dim dbs as database

set dbs = currentdb

strSql = SELECT name, address_no, phone FROM tblPerson WHERE person_no = " & Me.person_no & ";"

set rst = dbs.openrecordset(strSql, dbopensnapshot)

You could then use...

docmd.runsql "INSERT INTO tblPerson (name, address, phone) VALUES ( '" & rst!name & "', " & rst!address_no & ", " & phone & ");"

Note the single quotes used to break the sql statement so variable holding text can be used.

HTH
Chris

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top