Changing SQL statement used as form RecordSource

R

Rick Kunkel

Heya All,

I have a single form, and I want it to be usable with several queries.
It seems that people generally change the RecordSource property of the
form, and that's what I'm currently doing, with two buttons, like
this:

Private Sub btnFindContact_Click()
strfind = inputbox("Input Part of Contact Name")
strSQL = "select * from orgs where orgid in (select orgid from
contacts where ContactName like '%" & strfind & "%')"
DoCmd.OpenForm ("Orgs")
Forms![Orgs].RecordSource = strSQL
End Sub


Private Sub btnFindOrg_Click()
strfind = inputbox("Input Part of Organization Name")
strSQL = "select * from orgs where OrgName like '%" & strfind & "%'"
DoCmd.OpenForm ("Orgs")
Forms![Orgs].RecordSource = strSQL
End Sub

Essentially, the form needs to use one of the following two queries:

1. select * from Orgs where OrgName like '%{VARIABLE}%'

2. select * from Orgs where OrgID in (select orgid from contacts
where ContactName like '%{VARIABLE}%'

Is changing the RecordSource the best (only?) way to do this? Or are
there other ways?

Does the way I'm doing it look fine?

Thanks,

Rick Kunkel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top