.. e.g. LastName, FirstName, and ID.. My
problem is how will I organize the codes to filter the result based on the
entered data. If you have a similar database like this one, it would be
helpful.
just build a nice form, with 3 un-bound text boxes (txtLastName,
txtFirstName, txtID)
Remove all parameters from the sql...this makes the sql nice and clean, and
further, getting rid of all that junk and garbage out of the sql query means
that the query is NOT tied to a particular form, and you are free to use
that query anytime.
Note that the above is also better then query parameters since some of the
fields are now optional, and with parameters in a query, this is again a
very messy affair when you want to make some of the conditions optional.
So, now, just build the where clause in code. Assuming the above 3 fields,
you could then use the following code to launch the form (or report, as this
works great for that too).
dim strWhere as string
dim strSql as string
if isnull(txtLastName) = false then
strWhere = "LastName like '" & me.txtLastName & "*''
end if
strSql = strWhere
if isnull(txtFirstName) = false then
strWhere = "FirstName like '" & me.txtFirstName & "*''
end if
if strWhere <> "" then
if strSql <> "" then
strSql = strSql & " and "
end if
strSql = strSql & strWhere
end if
if isnull(txtID) = false then
strWhere = "id = " & id
end if
' at this point, you could open a form to show the matches
docmd.openForm "frmCustomer",,,strWhere
' or, you could stuff the results into a listbox, or lets assume a continues
subform.
me.MySubForm.Form.ReocrdSource = "select * from tblCustomers where " &
strWhere
I have some screen shots of the above code for a continues form here:
http://www.members.shaw.ca/AlbertKallal/Search/index.html
And, I have some screen shots for reports that also uses the above EXACT
same approach....
http://www.members.shaw.ca/AlbertKallal/ridesrpt/ridesrpt.html