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

Lookup Record in Form

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I have an index set on two fields in my database, SLIC and DATE. Therefore for every SLIC entry there can only be one date. On my form, the first two fields they enter are the SLIC and DATE. If they enter a SLIC and DATE that already exist I want it to pull the record and display it for editing etc. I'm using the On Exit event handler. This is the code I have so far.

I know that it is finding the record after trial and error, however I'm getting the following error:

"Microsoft Access Run-time Error '2105':
You can't go to the specified record.

You may be at the end of a recordset."

Here is my code:

Private Sub DATE_Exit(Cancel As Integer)
Dim db As DAO.Database, rst As DAO.Recordset
Dim strSearchName As String

Set rst = Me.RecordsetClone
strSearchName = "[SLIC] = " & Me![SLIC] & "AND [DATE] = #" & Me![DATE] & "#"

rst.FindFirst strSearchName
If rst.NoMatch Then
Exit Sub
Else
Me.Bookmark = rst.Bookmark
End If
rst.Close
End Sub
 
Hi,
Do you have a unique identifier (eg Primary Key) on this table? If so, instead of Me.Bookmark = rst.Bookmark try DoCmd.GoToRecord , , acGoTo, rst!UNIQUEIDFIELD

Kyle
 
I just tried that. No luck, I'm still getting that error 2105. I made sure that on my form you can edit/add records because I thought that might be the problem. This is confusing me...
 
Ok,
Is your form bound to the table of are you using an unbound form and recordsets?

I would assume it's bound, since you're using Me.RecordsetClone, but you gotta ask...

So, with that assumption I assume you're also having the form open up to "NewRecord" right?. So we need to ditch the "New Record" which was created as soon as the user typed into the fileds and then use GoTo

Out of curiosity, try this...

Me.Undo
DoCmd.GoToRecord , , acGoTo, rst!UNIQUEIDFIELD


Kyle ::)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top