Form Behaves differently when loaded from search vs. opened directly

Rachel Miller 21 Reputation points
2021-11-01T20:28:53.363+00:00

This is a stumper!

I have a set of forms designed to display search results. The forms are coded to sort by the column title when clicked and have some very basic "on open" code (I also tried adding this code to the "On Load" event, it made no impact):
Me.AllowAdditions = False
Me.AllowEdits = False
Me.AllowDeletions = False
Me.OrderBy = "LastName"
Me.OrderByOn = True

However, the only way a user can open any of these forms is through a search page that allows the user to choose all sorts of options.

At the end of the search function, I define the record source for the form:
SQL = "SELECT DISTINCTROW ParticipantContactandBackground., pAllProgramProcessProgress., pPlacementStatus.* FROM (ParticipantContactandBackground LEFT JOIN pAllProgramProcessProgress ON ParticipantContactandBackground.ParticipantID = pAllProgramProcessProgress.fkParticipantID) LEFT JOIN pPlacementStatus ON ParticipantContactandBackground.ParticipantID = pPlacementStatus.fkParticipantID WHERE " & Wh

DoCmd.OpenForm "PrimarySearchDemographics"
Forms!PrimarySearchDemographics.RecordSource = SQL

When the forms are opened from the search, the names are not sorted by last name and I cannot click on any of the column titles- nothing happens. As soon as I enter the VBA code for the page and switch back to form view, the sort function of the column titles works and the the form loads a list sorted by last name.

Any idea what the heck is happening here? I can't imagine why the form behaves so differently when I'm loading from the search function.

Happy to clarify further.
Thank you.

Access Development
Access Development
Access: A family of Microsoft relational database management systems designed for ease of use.Development: The process of researching, productizing, and refining new or existing technologies.
817 questions
0 comments No comments
{count} votes