"4004" <m.********@ntlworld.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
I would like to open a columnar form (so I can see all the details)
from a datasheet form (so I can see what is there) but keep the same
recordset and current record.
I can do the recordset set part (stlinkcriteria) - but how do I have
the new form open on the record that was current in the datasheet form?
I don't want to filter to the current record when the 2nd form opens -
I would like to be able to keep the whole rs and be able to go back and
forward to the other records.
The trick to this, is to write code in the second form's open event. This
code assumes that there is a table of contacts with a primary key ConID
which is a long integer (if the primary key is text then the code needs to
be adjusted slightly).
Private Sub Form_Open(Cancel As Integer)
On Error GoTo Err_Handler
Dim strOpenArgs As String
strOpenArgs = Trim(Nz(Me.OpenArgs, ""))
If Len(strOpenArgs) > 0 Then
Cancel = True
With Me.RecordsetClone
.FindFirst "ConID=" & strOpenArgs
If Not .NoMatch Then
Me.Bookmark = .Bookmark
Cancel = False
Else
MsgBox "Cannot locate contact no: " & strOpenArgs, _
vbExclamation, _
"Record location error"
End If
End With
End If
Exit_Handler:
Exit Sub
Err_Handler:
MsgBox Err.Description, vbExclamation, "Error No: " & Err.Number
Resume Exit_Handler
End Sub
Once this code is in there, you can then open the contacts form at a
particular record by calling
Docmd.OpenForm "frmContact",,,,,,"203"
Where "203" is an example ContactID, which, of course, would come from the
first form in your case.
If you don't supply a contact id, the form simply opens as normal. If you
do, then it will only open if it locates that record.