getting a string (VBA)

hello,

I want to get the return values for an unbound box (like a search results box):

the strWhere is where I want a query or if I can use a SQL code?

strWhere = "PersonID","qry","EntryPoint= & Form_myForm.txtGate"

(all values in the strwhere to be listed in the unbound box) BUT THE PIC DOESN'T SHOW IF I TRY TO USE A SQL:

 Capture.JPG
but using a query that calls for certain information:
something like:  
strWhere = "SELECT BackgroundCheck.PersonID, BackgroundCheck.EntryPoint, FROM BackgroundCheck, WHERE BackgroundCheck.Background Is Null AND BackgroundCheck.Entry= Wisconsin Gate"

Open in new window


Capture.JPG

Dim strWhere As String                  'The criteria string.
    
strWhere= 'don't know what to put here

strSQL = "SELECT MGNameAddressPhone.PersonID, MGNameAddressPhone.FName AS [First Name], MGNameAddressPhone.LName AS [Last Name], MGNameAddressPhone.LicenseNumber AS [Licence# (W/State)], FROM MGNameAddressPhone"

    strSQL = strSQL & " WHERE " & strWhere
    Me.SearchResults.RowSource = strSQL
    Me.SearchResults = Me.SearchResults.ItemData(1)
   

Open in new window


then when a user clicks the box the result they clicked on to open a new box:

A popup opens to a form that is looking at the unbound box
Private Sub SearchResults_Click()
DoCmd.OpenForm "frmmypopup"
End Sub

Open in new window

Ernest GroggAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ernest GroggAuthor Commented:
Maybe Get rid of the

strWhere and just use one

strSQL

???

SELECT MGNameAddressPhone.PersonID, MGNameAddressPhone.FName AS [First Name], MGNameAddressPhone.LName AS [Last Name], MGNameAddressPhone.LicenseNumber AS [Licence# (W/State)], FROM MGNameAddressPhone

but have an

INNERJOIN

but don't know how I would write this:

SELECT MGNameAddressPhone.PersonID, MGNameAddressPhone.FName AS [First Name], MGNameAddressPhone.LName AS [Last Name], MGNameAddressPhone.LicenseNumber AS [Licence# (W/State)], BackgroundCheck.Background, BackgroundCheck.EntryPoint
FROM BackgroundCheck INNER JOIN MGNameAddressPhone ON BackgroundCheck.PersonID = MGNameAddressPhone.PersonID
WHERE (((BackgroundCheck.Background) Is Null) AND ((BackgroundCheck.EntryPoint)=[forms]![frmSearchAllNameAddressPhone].[Form]![txtGate]));

Open in new window

0
PatHartmanCommented:
If I understand what you are trying do do, text box needs to be a subform.  You can recreate the Where clause if the criteria is variable.  Then put it in the RecordSource of the subform.

Me.MySubformcontrol.Form.RecordSource = strSQL
If the subform doesn't automatically refresh, add:
Me.MySubformcontrol.Form.Requery

Then in the click or double click event of one of the subform controls, you can use DoCmd.OpenForm to pass in a where argument and open the form to the selected record.
0
Ernest GroggAuthor Commented:
Trying to do a queue system, but the field is unbound.  Trying to reuse a search results box that I have.  currently it uses fields for the where

strSQL = strSQL & " WHERE " & strWhere


but want to change it to this:

strSQL= SELECT MGNameAddressPhone.PersonID, MGNameAddressPhone.FName AS [First Name], MGNameAddressPhone.LName AS [Last Name], MGNameAddressPhone.LicenseNumber AS [Licence# (W/State)], BackgroundCheck.Background, BackgroundCheck.EntryPoint
FROM BackgroundCheck INNER JOIN MGNameAddressPhone ON BackgroundCheck.PersonID = MGNameAddressPhone.PersonID
WHERE (((BackgroundCheck.Background) Is Null) AND ((BackgroundCheck.EntryPoint)=[forms]![frmSearchAllNameAddressPhone].[Form]![txtGate]));

Open in new window



so thinking here...how to write that sql statement I took from the Query, and write it for VBA?
0
PatHartmanCommented:
Text boxes hold strings.  They do not hold recordset objects.  If you want to create a subform on the fly, you can but I don't recommend it since it will prevent you from distributing the app as an .accde or from using the free runtime engine from using it since neither of those allow design changes to objects.

A subform is what you need to do what you want but a compromise might be a listbox.  You would need to set some properties such as the column widths and column count but you can change the recordsource and you can add code to the click event.  The problem is that unless you use some discipline in how you create the query so that the "key" column is always first and there is some way to identify what form you want to open, you won't be able to create common code to open the requested form.

Sounds like you might have experience in a different programming tool.  Access does not work they way you want it to.  The best course of action is to do things the "Access way" or use a different tool.  Access is far and away the best RAD tool on the marked for data-centric applications.  You seem to want it to build application objects on the fly.  That is not its intent and consequently, Access is not good at it.

If you can fix the columns, then using either a subform or a listbox will be easy to implement.  The where clause is easy to vary.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ernest GroggAuthor Commented:
yeah, so what i will do is create that as a subform and use a list box to change the data.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.