open form to specific record without filter

  • Thread starter Thread starter LGarcia
  • Start date Start date
L

LGarcia

Hi all,
I have 2 forms. Form1 contains a SubjectID field and a button. This button
opens Form2 which is filtered to the SubjectID on Form1.
This works fine. However, I occasionnaly need to refer to a previous
SubjectID. Removing the filter on Form2 takes me to the first record - not
what I want. Is there a way to open Form2 to the current SubjectID on Form1
that allows me to navigate to previous records?
Using AX07.
Thanks,
LGarcia
 
In the button's Click event procedure put:

Dim rst As Object
Dim frm As Form

DoCmd.OpenForm "Form2"

Set frm = Forms("Form2")
Set rst = frm.Recordset.Clone

With rst
.FindFirst "SubjectID = " & Me.SubjectID
If Not .NoMatch Then
frm.Bookmark = .Bookmark
End If
End With

Ken Sheridan
Stafford, England
 
Yes. You can do it but it gets cumbersome.

You will have to keep an archived history of SubjectID fields that you have
utilized from Form1. Then a button on Form2 would have to execute a new
filter based on the content of the archive.

Jack Cannon
 
Thanks!! I'll give it a try.

In the button's Click event procedure put:

Dim rst As Object
Dim frm As Form

DoCmd.OpenForm "Form2"

Set frm = Forms("Form2")
Set rst = frm.Recordset.Clone

With rst
.FindFirst "SubjectID = " & Me.SubjectID
If Not .NoMatch Then
frm.Bookmark = .Bookmark
End If
End With

Ken Sheridan
Stafford, England
 
You can add a public function to Form2, something like: Public Function
GoToRecord(recordID). Write code in that function to either move the form's
current record to the requested Primary Key value (using recordsetclone and
a bookmark), or write code that changes form's recordset to something like:
"Select * From Form2TableName Where tableID=" & recordID. Assign that sql
to Form2's RecordSource property, and that will become the only record in
Form2, without any filtering.

In Form1, include a line of code that calls
Form2.GoToRecord(desiredRecordID).

Or in Form2 you can have a button labeled "Go To Form1's Current Record",
and write similar code.
 

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

Back
Top