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

FindRecord error 1

Status
Not open for further replies.

belovedcej

Programmer
Nov 16, 2005
358
US
Okay - I have done this successfully before but today I'm hitting my head up against a wall. . .

After editing a record in my frmEventsEdit form, I want to restore frmEvents to visibility and return to the same record, if it was a record edit, not a record add.

I'm getting the message that there is an error in my Find record argument. So my final attempt was to set the pertinent field visible, focus on it, and then do my find.

Still no go - I have an error.

Here's the portion that I'm referring to (my intEventID is declared and initialized earlier in the sub.)

Code:
Form_frmEvents.txtEventID.Visible = True
Form_frmEvents.txtEventID.SetFocus

If intEventID > 0 Then
    DoCmd.FindRecord intEventID, , , , , acCurrent
End If

Form_frmEvents.txtEventID.Visible = False

DoCmd.Close acForm, "frmEventsEdit"

 
Is frmEvents bound?


The usual way of finding a record is to say something like (typed, not tested):
Code:
Set rs= Me.RecordsetClone
rs.FindFirst "ID=" & intEventID 
If Not rs.NoMatch
  Me.Bookmark=rs.Bookmark
Else
  'What ever
End If
 
yes - frmEvents is bound - and uneditable. frmEventsEdit is unbound and when a user clicks the button to edit a record, it opens with only the values from that single record. If a record is being added instead of edited, frmEventsEdit opens with empty fields.

I've never worked with clones or bookmarks before - so bear with me. . . :)

You are suggesting that I:

Clone the recordset of my bound form and do the search within that clones recordset?

(I would have to do a Form_frmEvents.RecordsetClone because this routine is being activated from an on_click routine on frmEventsEdit, if I am understanding this correctly.)

And does bookmarking then open the form to the matching record?


I'll give it a try. .. .
 
Okay - this worked well - thanks!! I was able to open the record at the right spot.

I did the following:

Code:
Dim rs As New Recordset
Set rs = Form_frmEvents.RecordsetClone
rs.Find "[Event_ID]=" & intEventID
Form_frmEvents.Bookmark = rs.Bookmark


I was unable to find any property of the recordset that was similar to a "match" or "non match" - but I may be able to work around that because I will just check for the value of the ID before doing the search.

Thanks for the help!
 
Yes, that is the general idea:
Code:
Set rs = Form_frmEvents.RecordsetClone
rs.FindFirst "ID=" & intEventID
If Not rs.NoMatch Then
  Form_frmEvents.Bookmark = rs.Bookmark
Else
  'What ever
End If

FindRecord as you are using it will not work, as far as I know.
 
Oops, crossed in the post. I should have mentioned, I used a DAO Recordset, which needs a refernce to the Microsoft DAO x.x Object library.
 
ah - DAO. Should have known. I tried it as ADODB since this is an adp file and nearly all my work is done with ADO recordsets. So I didn't think of DAO.

BTW - I have, even in this same project, been able to make the FindRecord work - with the saem syntax. But there's obviously something I don't understand about what I'm doing, because sometimes, like here, it doesn't work.

Now that i understand this, I'll just use this way form now on.

Once again, thank you so much!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top