Another Sychronizing Forms Question

clf

New member
Local time
Today, 18:07
Joined
Jan 9, 2001
Messages
8
I am pretty new at Access, so forgive me if this is a dumb question. Is there a way that I can use a command button to open a form and display a certain record on that form without filtering out all of the other records? I want to use a command button to open a form from another form, but have the two form be in sync with each other.

Example, I'm viewing a record with ID #3 on form 1 and I want to be able to click a button that lets me open form 2 and view ID#3, without filtering out all of the other records.

Any help would be appreciated, thanks.
 
You have two forms - frmA and frmB.
frmA is based on some table/query.
frmA has a command button cmdOpenfrmB
frmA has a textbox control txtID which stores the ID# you mentioned in your question.
frmB is based on the same table/query as frmA

In frmA you would have the following event procedure:

Private Sub cmdOpenfrmB_Click()
docmd.openform "frmB",,,,,,me.txtID
End Sub

Note:I'm not sure how many commas there are supposed to be, but the me.txtID argument is supposed to be the last one - the openargs argument.

In frmB you would have this event:

Private Sub Form_Load()
Me.RecordsetClone.FindFirst "[CategoryID] = " & Val(Me.OpenArgs)
Me.Bookmark = Me.RecordsetClone.Bookmark
End Sub

What this does is creates a recordset object you can reference. This objects allows you to use methods that are reserved to recordset objects on a form which is based on a table/query.
The Val(me.openarg) the the me.txtID value you had passed in the command button OnClick event from frmA.
I used the Val procedure to convert the me.openarg to an integer value since me.openarg is a text value. If the field you specified was a text field then you would simply pu me.openarg, leaving out the val function.

The line 'Me.bookmark = me.recordsetbookmark' is what causes frmB to display the record you want it to. the findfirst method moves to the record which satisfies the criteria you specified. But in the me.recordsetclone object. The bookmark value is a sort of marker so when you assign it to the forms bookmark you make the current record of the form the same as in the recordset object. If you left out that line the form would go to teh first record.

This was a very good question. I had never tried anything like this before but I'm sure there were situations where I used much more code and created more objects to accomplish the same thing.

ntp
 

Users who are viewing this thread

Back
Top Bottom