Passing last sort command to DoCmd.OpenForm

Danick

Registered User.
Local time
Today, 15:39
Joined
Sep 23, 2008
Messages
371
I have a continuous form that shows a summary list of records. And another form that is a single form that will only show filtered records that were selected from the 1st form.

The summary form has some combo filters and a command button that opens the second form with only the filtered records. I am using Allen’s Brown’s sample of strWhere to do this.



http://allenbrowne.com/ser-62.html


DoCmd,OpenForm “frmName”,,,strWhere

I also have a few sort command buttons that are using the Me.Orderby=”[FieldName]”

What I can not figure out is how to pass the last sort command from the summary form along with the where condition to the second form.

Any ideas?
 
You are using the OpenArgs to pass the info between your two forms. As the OpenArgs can hold only one string at a time, you will need to Concatenate your two strings and use a distinct character such as a hash (#) to indicate the end of your first string and the start of the second. You can then use this character to split the two strings in the second form.
 
Sorry my bad :o you are using the Where Clause of the DoCmd.OpenForm to open the form filtered to your requirements. So you can simply pass the last sort command in the OpenArgs. Which you can then test and apply in the On Load event of the second form.
 
Sorry my bad :o you are using the Where Clause of the DoCmd.OpenForm to open the form filtered to your requirements. So you can simply pass the last sort command in the OpenArgs. Which you can then test and apply in the On Load event of the second form.

Thanks for your reply.
Got any examples as to how to do this?
 
Have a look at the sample here. Specifically look a the Double Click event for Combo2 on FRM_Records, and On Load event of FRM_Items.
 
Have a look at the sample here. Specifically look a the Double Click event for Combo2 on FRM_Records, and On Load event of FRM_Items.

I tried to follow your example, but I can’t get it to work. Here is what I am trying to do.

The first form has buttons that will sort the continuous form. One of these buttons is for contacts. So I would like to capture this last sort action and pass the sort to the second form. I am using the string strOrderBy to try to do this

Dim strOrderBy As String
Me.OrderBy = "[ContactName] ASC"
Me.OrderByOn = True
strOrderBy = Me.OrderBy

After the sort button is pressed, I want the next command button that opens the second form to sort by whatever was in the StrOrderBy

Private Sub Command66_Click() 'Open 2nd form filtered and sorted
Dim strWhere As String 'The criteria string.
Dim strOrderBy As String

DoCmd.OpenForm "frm2ndform", , , strWhere, , , Me.strOrderBy

And finally, I put the OpenArgs in the second form that I am trying to pass the sort order to:

Private Sub Form_Load()
If Not IsNull(Me.OpenArgs) Then
Me.OrderBy = Me.strOrderBy
Me.OrderByOn = True
End If


But this just gives me a Compile error: Method or data member not found
With strOrderBy highlighted in the Open form command
DoCmd.OpenForm "frm2ndform", , , strWhere, , , Me.strOrderBy


Any ideas on what I’m doing wrong?
Thanks
 
You don't need to pass anything.

Simply sort it after the OpenForm command.
Code:
DoCmd.Openform ...etc
Forms!Form2.OrderBy = Me.OrderBy
Forms!Form2.OrderByOn = True
 
You don't need to pass anything.

Simply sort it after the OpenForm command.
Code:
DoCmd.Openform ...etc
Forms!Form2.OrderBy = Me.OrderBy
Forms!Form2.OrderByOn = True

WOW!! That was really simple and it works.
Thanks..
 

Users who are viewing this thread

Back
Top Bottom