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!

My code always edits first record??

Status
Not open for further replies.

bobleonard

Programmer
Mar 28, 2002
32
US
This code, though it moves to the record I input, it always edits record number 1. The ID field is an auto-number field. I put this code together from examples but I don't know what I'm doing wrong.
Thanks for any input. I took out the 'useful' code because it doesn't matter for 'Edit' problem. I move to correct record but alway Edit record #1


Private Sub Command232_Click()


Dim dbsThisOne As DAO.Database
Dim rs As DAO.Recordset


Dim recnum, recsave As Long

On Local Error GoTo FormFindREcord_Err
Set dbsThisOne = CurrentDb

Set rs = dbsThisOne.OpenRecordset("People", dbOpenDynaset)

recnum = InputBox("enter the record Number to Import")
recsave = recnum


Me!ID.SetFocus

Me!ID.Enabled = True
DoCmd.GoToControl "ID"

DoCmd.FindRecord recnum, , True, , True

Refresh
MsgBox ("Did a move to that Record?") 'debug

rs.Edit

'Add data

rs!Dpoint1 = recnum

'Commit the changes
rs.Update

skipupdate:

rs.Close
Set rs = Nothing
dbsThisOne.Close
Set dbsThisOne = Nothing

GoTo exithere

FormFindREcord_Err:

MsgBox Err.Description
Resume exithere

exithere:

End Sub
 
How are ya bobleonard . . .

Key here is when you set rs:
Code:
[blue]Set rs = dbsThisOne.OpenRecordset("People", dbOpenDynaset) [green]' the record pointer for rs now sits at the 1st record.[/green][/blue]
Then you search for ID on the form ... not in the recordset
Code:
[blue]DoCmd.FindRecord recnum, , True, , True[/blue]
Then when you [blue]rs.Edit[/blue] you edit the 1st record in [blue]rs[/blue].

Your find should be:
Code:
[blue]   rs.FindFirst "[ID] = " & recnum[/blue]
[blue]Your Thoughts? . . .[/blue]

See Ya! . . . . . .

Be sure to see faq219-2884 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top