For this question, I have built a simple DataBase, an AddressBook, because that is understandable to everyone, I don't need to spend effort explaining my issue, I can confine my discussion to Access. I have 2 tables.
Table = tAAA is as follows:
Expand|Select|Wrap|Line Numbers
- Key Data
- 1 Wanted to be President of USA
- 2 Was President of USA
- 3 WWII General who became President of USA
Expand|Select|Wrap|Line Numbers
- Key Pointer Type Name
- 1 1 2 Bobby Kennedy
- 2 3 2 Ike Eisenhower
- 3 2 2 Jack Kennedy
- 4 1 3 Robt. Kennedy
- 5 2 1 John F. Kennedy
- 6 3 1 Dwight David Eisenhower
- 7 1 1 Robert F. Kennedy
To keep it simple here, there are 4 controls on the Form fAAA
txtSearch, a TextBox where User enters partial name to display in lbxNames
chkShowAlt, a CheckBox to specify whether Type=2 names are displayed. Type=1 are always displayed, Type=3 are never displayed.
lbxNames, a Listbox to display names as qualified by txtSearch and chkShowAlt
txtDisplay, a TextBox to display all bound data, but for this example, the field tAAA.Data. This is a simple test program, remember.
3 examples -
1) User enters "Kennedy", lbxNames should contain:
4 names if chkShowAlt=True
Bobby Kennedy
Jack Kennedy
John F. Kennedy
Robert F. Kennedy
2 names if chkShowAlt=False
John F. Kennedy
Robert F. Kennedy
2) User enters "Robt", lbxNames should contain:
2 names if chkShowAlt=True
Bobby Kennedy
Robert F. Kennedy
1 name if chkShowAlt=False
Robert F. Kennedy
3) User enters "Bob", lbxNames should contain:
2 names if chkShowAlt=True
Bobby Kennedy
Robert F. Kennedy
1 name if chkShowAlt=False
Robert F. Kennedy
The SQL Statement "SELECT tNames.Pointer, tNames.Name FROM tNames WHERE (((tNames.Name) Like ""*Bob*""));" returns the row with Key=1 & Name="Bobby Kennedy". I have saved this query as qStep1.
The SQL Statement
Expand|Select|Wrap|Line Numbers
- "SELECT tNames.Key, tNames.Name
- FROM tNames INNER JOIN qStep1
- ON tNames.Pointer = qStep1.Pointer
- WHERE (((tNames.Type)<3))
- ORDER BY tNames.Name;"
That is exactly correct, and exactly what I want to do!!! But . . . I want a single SQL statement, if possible. I want to replace the "qStep1" with "SELECT tNames.Pointer . . .". Does this go in parens "()"? How do I refer to "qStep1.Pointer" when qStep1 becomes a SELECT Statement?
OIdBirdman