RLN <nospamrln@[EMAIL PROTECTED]
> wrote in
news:1209753995_2915@[EMAIL PROTECTED]
> I have an option group control with 2 choices:
> Sort ASC and Sort DESC
> When this choice is made, I want to change the recordsource for
> the current form and do a refresh so it sorts that data in the
> order specified by the option group.
>
> When it gets to the line Me.Recordsource" it errors out with
> "Object cannot sup****t this property or method."
>
> I've already tried:
> Forms!frmMyformName.setfocus (prior to changing the recordsource)
> as well as:
> Forms!frmMyformName.recordsource = "Select * from..." and that
> does not work either."
>
> When I am in a subroutine for ControlX that exists on FormX, what
> is the proper syntax for changing FormX's recordsource and doing
> a refresh of the form while ControlX inside that form has the
> focus?
>
> (here's the code so far)
>
> Private Sub optSortMethod2_Click()
> On Error GoTo Err1
> Dim strSortBy As String
> Dim strSelect As String
> cmbSort.SetFocus
> strSortBy = "order by " & cmbSort.Text
> Select Case optSortMethod2.Value
> Case 1
> strSortBy = strSortBy & " Asc"
> Case 2
> strSortBy = strSortBy & " Desc"
> Case Else
> 'do nothing here
> End Select
>
> Me.RecordSource = "Select * from tblMyTable where DATEREC BETWEEN
> #" & lblFromDate & "# AND #" & lblToDate & "#" & strSortBy
>
> ' Forms!frmHistory.SetFocus
> ' Forms!frmHistory.RecordSource = "Select * from tblMyTable where
> DATEREC BETWEEN #" & lblFromDate & "# AND #" & lblToDate & "#" &
> strSortBy
> ' Me.Refresh
>
> Exit1:
> Exit Sub
> Err1:
> MsgBox Err.Number & "-" & Err.DESCRIPTION, vbOKOnly,
> gblPgmTitle &
> gblPgmErrorTag & "-optSortMethod2_Click()"
> Resume Exit1
>
> End Sub
>
>
>
> *** Sent via Developersdex http://www.developersdex.com
***
AS bruce has pointed out, the lblFromDate, lblToDate references are
incorrect if they are in fact referring to labels.
But I ask why change the recordsource at all just to change the sort
order?
Forms have an .OrderBy property that you can use to reorder a form
much more quickly than changing the recordsource of the form.
There is an additional property, .OrderByOn which needs to be set
true or false.
From the help in Access 2003
The OrderBy property is a string expression that is the name of the
field or fields on which you want to sort records. When you use more
than one field name, separate the names with a comma (,).
If you want to sort records in descending order, type DESC at the
end of the string expression. For example, to sort customer records
in descending order by contact name, set the OrderBy property to
"ContactName DESC".
There is also a Filter property, and a FilterOn property to go with
it.
--
Bob Quintal
PA is y I've altered my email address.
** Posted from http://www.teranews.com
**


|