Set a forms order by through VB

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a form that I open from another form based on a series of buttons.
Depending on which button the person hits I want the 2nd form to open in a
specific sequence. How can I do this through VB.
 
I have a form that I open from another form based on a series of buttons.
Depending on which button the person hits I want the 2nd form to open in a
specific sequence. How can I do this through VB.

Several ways. Here's one.

DoCmd.OpenForm "FormName"
If [Button1] then
forms!FormName.OrderBy = "TableName.[LastName] Desc"
ElseIf [Button2] Then
forms!FormName.OrderBy = "TableName.[LastName] Asc"
Else
forms!FormName.OrderBy = "TableName.[City]"
End If
forms!FormName.OrderByOn = True

You could also pass the field name using the OpenArgs argument and
reading it in the new form Load event.
 
Thank you very much. Worked great.
--
M. Shipp


fredg said:
I have a form that I open from another form based on a series of buttons.
Depending on which button the person hits I want the 2nd form to open in a
specific sequence. How can I do this through VB.

Several ways. Here's one.

DoCmd.OpenForm "FormName"
If [Button1] then
forms!FormName.OrderBy = "TableName.[LastName] Desc"
ElseIf [Button2] Then
forms!FormName.OrderBy = "TableName.[LastName] Asc"
Else
forms!FormName.OrderBy = "TableName.[City]"
End If
forms!FormName.OrderByOn = True

You could also pass the field name using the OpenArgs argument and
reading it in the new form Load event.
 
Back
Top