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

Going to a specific record after Copy Command

Status
Not open for further replies.

jbento

Technical User
Jul 20, 2001
573
US
All,
I have 3 forms. One is a search form and the other is a results form, and then there is a results form from a button that copies a record.

I have a command button on the results form to copy that record.

Once that record is copied it opens up the form with the copied information, but the only problem it doesn't open to the record that was copied. It opens up to some other record in the database.

Does anyone know of code I can use to get the results of the specific record I just copied?

Any help would definitely be appreciated.

Thanks in advance,

Jerome Benton
JERPAT Web Designs
GOD Is Good All The Time!!!
 
This does not work, because the record that is copied is not normally going to be the last record.

I just tried it and it is bringing up some other record still.

Any other ideas?

Jerome Benton
JERPAT Web Designs
GOD Is Good All The Time!!!
 
Take a look at the RecordsetClone, FindFirst, NoMatch and Bookmark methods/properties of the DAO.Recordset and Form objects.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Ok. Yes I tried this, but how I have this set up that doesn't work.

I thought of something else. What if I put a command in my copy command to force the newly created to be the last record?

Here is my code:
Private Sub Command10_Click()

Dim db As DAO.Database, rst As DAO.Recordset

'Copy Record
Set db = CurrentDb
Set rst = db.OpenRecordset("tbl_Test")
rst.AddNew

rst!field1 = Me!field1
rst!field2 = Me!field2
rst!field3 = Me!field3

rst.Update
rst.Close
db.Close

DoCmd.OpenForm "frm_CopyResults", acNormal, "", "",, acNormal
DoCmd.GoToRecord,, acLast

End Sub

With the code above how could I modify by forcing the copy to be the last record in the table?

I tried to put in something like rst.MoveLast in the code, but that doesn't do it.

Can someone help me with this?

Thanks in advance again,

Jerome Benton
JERPAT Web Designs
GOD Is Good All The Time!!!
 
How are ya jbento . . . . .

You can use the Open Args of the DoCmd.OpenForm to pass the PK of the copied record. So in your button code, put the following code:
Code:
[blue]DoCmd.OpenForm "frm_CopyResults", acNormal, , , , , Me![purple][b]YourPKname[/b][/purple][/blue]
Then in the [blue]OnLoad[/blue] event of your [blue]frm_CopyResults[/blue] add the following code:
Code:
[blue]   Dim rst As dao.Recordset
   
   Set rst = Me.RecordsetClone
   rst.FindFirst "[purple][b]PKname[/b][/purple] = " & Me.[purple]OpenArgs[/purple]
   Me.Bookmark = rst.Bookmark
   Set rst = Nothing[/blue]

Calvin.gif
See Ya! . . . . . .
 
TheAceMan1,
I'm doing good my friend, but I may have a stupid question.

What is PK?

Jerome Benton
JERPAT Web Designs
GOD Is Good All The Time!!!
 
What is PK?
PK stands for Primary Key.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Ok I know what that is, but I just don't use acronyms very much, because my job is HUGE on using acronyms for everything:)

Thanks my friend,

Jerome Benton
JERPAT Web Designs
GOD Is Good All The Time!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top