Niklas Östergren said:
Hmm, strange!
I´v got it to work now (but for how longe I don´t know).
What i didd is to open up the subform in design mode and delete
propertie "Sort By" (which was [LastName] & [FirstName]).
I sort the subform using a combobox on the mainform where the user can
select different criteria to sort by (see code below).
Any ídéas what may have caused this and what I could do to prevet it
from happening in the future?
TIA!
// Niklas
Using this code to sort the subform:
==============================================================
Private Sub cboSortOrder_AfterUpdate()
Dim frm As Form
Dim strSQL As String
Set frm = Me.frmsubListMembers.Form
' Set record source
frm.RecordSource = "qryValidMemberShip"
' Select sort order for form frmsubListMembers
Select Case Me.cboSortOrder
Case "Efternamn"
frm.OrderBy = "[LastName] & [FirstName]"
frm.OrderByOn = True
strSQL = "SELECT PersonID, LastName & ' ' & [FirstName] "
_ & " & ', ' & Street AS searchSource " _
& "FROM qryValidMemberShip " _
& "ORDER BY LastName & [FirstName]"
Me.cboSearchfrmsubListMembers.RowSource = strSQL
Case "FödelseDatum"
frm.OrderBy = "[DoB]"
frm.OrderByOn = True
strSQL = "SELECT PersonID, DoB & ', ' & LastName " _
& " & ' ' & [FirstName] AS searchSource " _
& "FROM qryValidMemberShip " _
& "ORDER BY DoB"
Me.cboSearchfrmsubListMembers.RowSource = strSQL
Case "Förnamn"
frm.OrderBy = "[FirstName] & [LastName]"
frm.OrderByOn = True
strSQL = "SELECT PersonID, [FirstName] & ' ' & LastName "
_ & " & ', ' & Street AS searchSource " _
& "FROM qryValidMemberShip " _
& "ORDER BY [FirstName] & LastName"
Me.cboSearchfrmsubListMembers.RowSource = strSQL
Case "Medlemsnummer"
frm.OrderBy = "[MemberNo]"
frm.OrderByOn = True
strSQL = "SELECT PersonID, MemberNo & ', ' & LastName " _
& " & ' ' & [FirstName] AS searchSource " _
& "FROM qryValidMemberShip " _
& "ORDER BY MemberNo"
Me.cboSearchfrmsubListMembers.RowSource = strSQL
Case Else
frm.OrderBy = "[LastName] & [FirstName]"
frm.OrderByOn = True
strSQL = "SELECT PersonID, LastName & ' ' & [FirstName] "
_ & " & ', ' & Street AS searchSource " _
& "FROM qryValidMemberShip " _
& "ORDER BY LastName & [FirstName]"
Me.cboSearchfrmsubListMembers.RowSource = strSQL
End Select
' Set focus to subform control and requery
Me.frmsubListMembers.SetFocus
' Requery cboSearchfrmsubListMembers
cboSearchfrmsubListMembers.Requery
' Set focus on cboSearchfrmsubListMembers
Me.cboSearchfrmsubListMembers.SetFocus
Set frm = Nothing
End Sub
===============================================================
I'm not sure what's going on, Niklas, but there are some things in that
code that I don't quite follow. First, why are you resetting the
subform's recordsource, with
' Set record source
frm.RecordSource = "qryValidMemberShip"
, every time cboSortOrder is updated? Is there some reason to believe
it has changed? Are you aware that changing a form's RecordSource
property forces a requery of the form?
Second, your explicit requery of cboSearchfrmsubListMembers, with
' Requery cboSearchfrmsubListMembers
cboSearchfrmsubListMembers.Requery
, isn't necessary, because your earlier code changes its RowSource
property, and changing the RowSource property of a combo or list box
forces a requery of the control.
I also don't understand why you are setting the focus first to the
subform control and then to the combo box on the main form. There would
seem to be no point in setting the focus to the subform control,
although I guess it's harmless.
I note that you are continually sorting by the expression [LastName] &
[FirstName], rather than sorting by the two fields themselves:
[LastName], [FirstName]. Are you doing this on purpose, to get a rather
unusual sort order? Consider: the following records are shown in the
order resulting from "Order By LastName, FirstName":
LastName FirstName
----------- -----------
A BCDEF
AB CDE
ABC D
Here's the result of "Order By LastName & FirstName":
LastName FirstName
----------- -----------
ABC D
AB CDE
A BCDEF
So it makes a significant difference how you specify your Order By
clause in a query, or the Order By property of a form. Also note that
if you have indexes on LastName and FirstName, "Order By LastName &
FirstName" won't be able to take advantage of them, but "Order By
LastName, FirstName" will.
All that doesn't help much with the specific problem of your
txtRecordCount control. Possibly you are changing the subform's
recordsource before your code has a change to pick up the value. But
why not just put a control in the subform's form footer (even if that
footer is set to be invisible), with its ControlSource set to
"=Count(*)" ? Then you could have a calculated control on the main form
that just picks up the count value from that control on the subform, and
I don't think any code would be needed.
--
Dirk Goldgar, MS Access MVP
www.datagnostics.com
(please reply to the newsgroup)