Move to a new added record

B

BrunoKP

After having added a new record with among others an index field "NID", I
want to display the new record in the Form. I have tested with the following
code, but end up in the NoMatch line. I have traced that the right value of
NID in the new record is assigned correctly to strSearchName, but apparently
the new record has not yet been added to RecordsetClone. Do you have a
solution for me?

Set rst = Me.RecordsetClone
strSearchName = NID
rst.FindFirst "NID = " & strSearchName
If rst.NoMatch Then
MsgBox "Record not found"
Else
Me.Bookmark = rst.Bookmark
End If
rst.Close
 
R

Ralph

Is NID a text field. I would assume that because your variable is
strSearchName?

You left out the single quotes.

Set rst = Me.RecordsetClone
strSearchName = Me!NID
rst.FindFirst "[NID] = '" & strSearchName & "'"
 
B

BrunoKP

I am sorry for the late response, I has been busy with other problems.
NID is not a text field, but a "Long" variable in the subroutine.
When I debug stepwise, I can see that NID has got the right value
corresponding to the new record, and "strSearchName" has the right content,
but I still end up in the NoMatch line.
After the subroutine has been finished the number of records has not been
updated in the form, so I have to press the button "refresh all" (translated
from danish) in the top and middle of the tool bar.
It seems to me that the "rst" has not yet been updated with the new record.
Hope to get some help.

"Ralph" skrev:
Is NID a text field. I would assume that because your variable is
strSearchName?

You left out the single quotes.

Set rst = Me.RecordsetClone
strSearchName = Me!NID
rst.FindFirst "[NID] = '" & strSearchName & "'"


BrunoKP said:
After having added a new record with among others an index field "NID", I
want to display the new record in the Form. I have tested with the following
code, but end up in the NoMatch line. I have traced that the right value of
NID in the new record is assigned correctly to strSearchName, but apparently
the new record has not yet been added to RecordsetClone. Do you have a
solution for me?

Set rst = Me.RecordsetClone
strSearchName = NID
rst.FindFirst "NID = " & strSearchName
If rst.NoMatch Then
MsgBox "Record not found"
Else
Me.Bookmark = rst.Bookmark
End If
rst.Close
 
B

BrunoKP

I found the answer elsewhere: In front of the code below I had
Me. Refresh
It has been changed to:
Me.Requery
Kind regards Bruno

"BrunoKP" skrev:
 

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