going to the newly added record

  • Thread starter SElgin via AccessMonster.com
  • Start date
S

SElgin via AccessMonster.com

i have the following code in the OnCurrent event of my form. Ut is supposed
to find the newly added record based on the Id. Id is the PK and NewId is
the newly added Id number.

If Not IsNull(Me.NewId) Then
Dim rs As DAO.Recordset
Set rs = Me.RecordsetClone
'rs.FindFirst "[Id] = " & ""[NewId]""
rs.FindFirst "[id] = " & "NewId"
If rs.NoMatch Then
MsgBox "This id not found"
Else
Me.Bookmark = rs.Bookmark 'synch the form to the found record
End If
End If

I could not find an applicable thread so TIA for the help

Steve
 
M

Mike Painter

SElgin said:
i have the following code in the OnCurrent event of my form. Ut is
supposed to find the newly added record based on the Id. Id is the
PK and NewId is the newly added Id number.

If Not IsNull(Me.NewId) Then
Dim rs As DAO.Recordset
Set rs = Me.RecordsetClone
'rs.FindFirst "[Id] = " & ""[NewId]""
rs.FindFirst "[id] = " & "NewId"
If rs.NoMatch Then

Is NewID a number?
'rs.FindFirst "[Id] = " & NewId
or
'rs.FindFirst "[Id] = " & me.NewId

If not

'rs.FindFirst "[Id] = '" & [NewId] &"'"
single quote double quote after the equal sign and double quote, single
quote, double quote at the end.
 
S

SElgin via AccessMonster.com

Mike said:
i have the following code in the OnCurrent event of my form. Ut is
supposed to find the newly added record based on the Id. Id is the
[quoted text clipped - 6 lines]
rs.FindFirst "[id] = " & "NewId"
If rs.NoMatch Then

Is NewID a number?
'rs.FindFirst "[Id] = " & NewId
or
'rs.FindFirst "[Id] = " & me.NewId

If not

'rs.FindFirst "[Id] = '" & [NewId] &"'"
single quote double quote after the equal sign and double quote, single
quote, double quote at the end.

NewId is a number, I put an unbound textbox on the form and the number shows
correctly. I interpret this to mean that I am getting the correct Id number
when I add a record. I formated the textbox as a number so that should mean
that rs.FindFirst "[Id]= " & NewId should work and it doesnt.

Thanks for the help.
Steve
 
M

Mike Painter

SElgin said:
Mike said:
i have the following code in the OnCurrent event of my form. Ut is
supposed to find the newly added record based on the Id. Id is the
[quoted text clipped - 6 lines]
rs.FindFirst "[id] = " & "NewId"
If rs.NoMatch Then

Is NewID a number?
'rs.FindFirst "[Id] = " & NewId
or
'rs.FindFirst "[Id] = " & me.NewId

If not

'rs.FindFirst "[Id] = '" & [NewId] &"'"
single quote double quote after the equal sign and double quote,
single quote, double quote at the end.

NewId is a number, I put an unbound textbox on the form and the
number shows correctly. I interpret this to mean that I am getting
the correct Id number when I add a record. I formated the textbox as
a number so that should mean that rs.FindFirst "[Id]= " & NewId
should work and it doesnt.

If it is unbound the number does not come from a table.

What is the name of the unbound textbox? Unless it is NewID you will not get
anything.
Oops, not that it would anyway. If the ID is not in the table findfirst will
never find it.
 
S

SElgin via AccessMonster.com

Mike said:
[quoted text clipped - 18 lines]
a number so that should mean that rs.FindFirst "[Id]= " & NewId
should work and it doesnt.

If it is unbound the number does not come from a table.

What is the name of the unbound textbox? Unless it is NewID you will not get
anything.
Oops, not that it would anyway. If the ID is not in the table findfirst will
never find it.
Id is the PK of the table. NewId is the Id number of a newly added record
from the add record form.
Id is of course bound on the form but NewId is not. NewId shows the correct
number after adding a record, but it doesn't change to that record.

Thanks for the help
Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top