Populate ListBox with different query using openArgs

  • Thread starter Thread starter Saul
  • Start date Start date
S

Saul

FrmMain allows user to enter in a LastName in txtLastName.
The user then clicks cmdOKLastName. This opens frmResults
on which ListBoxResults contains the results of QryA
(selects all clients in my database with that LastName).
ListBoxResults on frmResults displays the results of QryA.
I'm trying to make it so that the user also can search for
a client by entering the DOB in a different txt box on
FrmMain and click cmdOKDOB. Using the openArgsproperty of
DoCmd Open Form method, I am trying to get ListBoxResults
on frmResults to display the results of either QryA or
QryB (selects all clients with that DOB) depending on
which cmdOK button was selected by the user.

Or would it make more sense to alter the qry criteria
(change from[Forms!][FrmMain].[LastName]in the LastName
column to [Forms!][FrmMain].[DOB] in the DOB column) based
on the entry made by the user?

Sorry to ramble on. Hope this makes sense. Thanks.
 
Hi Saul,
with the objective of avoiding duplication, as the columns
returned in the listbox seem to be the same, use the same
base query; just change the criteria.

for example pass the where condition in the OpenArgs

Private sub DisplayResults(WhereCondition as string)
docmd.openform
FormName:="frmResults",OpenArgs:=WhereCondition
End Sub

private sub cmdOKDOB_Click()
DisplayResults "([DOB]=" & txtDOB & ")"
end sub

private sub cmdOKLastName_Click()
DisplayResults "([LastName]=" & txtLastName & ")"
end sub

' in frmResults
private sub Form_OnLoad()
if not isnull(me.openargs) then
ListBoxResults.rowsource="Select QryResults.* From
QryResults " _
& "Where " & me.openargs & ";"
end if

Luck
Jonathan
Luck
Jonathan
-----Original Message-----
FrmMain allows user to enter in a LastName in txtLastName.
The user then clicks cmdOKLastName. This opens frmResults
on which ListBoxResults contains the results of QryA
(selects all clients in my database with that LastName).
ListBoxResults on frmResults displays the results of QryA.
I'm trying to make it so that the user also can search for
a client by entering the DOB in a different txt box on
FrmMain and click cmdOKDOB. Using the openArgsproperty of
DoCmd Open Form method, I am trying to get ListBoxResults
on frmResults to display the results of either QryA or
QryB (selects all clients with that DOB) depending on
which cmdOK button was selected by the user.

Or would it make more sense to alter the qry criteria
(change from[Forms!][FrmMain].[ DisplayResults "([DOB]="
& txtDOB & ")"
end sub
]in the LastName
column to [Forms!][FrmMain].[DOB] in the DOB column) based
on the entry made by the user?

Sorry to ramble on. Hope this makes sense. Thanks.
.
 
Back
Top