On Open code to find record

J

Jim

I have 2 forms where the second form may or may not have records related to
the first form. There is a link to the second form from the first one. What
I'm trying to accomplish is to open the second form displaying the related
record if there is one.

Form 1 is OA
Form 2 is Register

linking fiels are:
OA.ID = Register.EventID

Not every OA.ID has a related Register.EventID.

If there is a related record, I would like the Register form to open with
that record displayed. If not, just open the form in normal view which sets
focus to a combo box and all other fields are invisible until a selection is
made.
 
J

Jack Leach

Generally what I do is pass the wanted ID via OpenArg to the second form,
then check the args and move to that record if there's one...


On form 1 button to open form2:

DoCmd.OpenForm "form2", , , , , , , Me.ID


on the Open event of form2

(aircode)
Dim rs As DAO.Recordset
If Len(Nz(Me.OpenArgs, "")) <> 0 Then
Set rs = Me.RecordsetClone
With rs
.FindFirst "[EventID] = " & CLng(Me.OpenArgs)
If Not .NoMatch Then
Me.Bookmark = rs.Bookmark
End If
End With
End If
Set rs =Nothing



not quite sure how you would accomplish this with a link... if it's an
actualy hyperlink you may be able to format a label with the text to make it
appear as a hyperlink and run OpenForm from the labels click event


hth
--
Jack Leach
www.tristatemachine.com

"I haven''t failed, I''ve found ten thousand ways that don''t work."
-Thomas Edison (1847-1931)
 

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