Hi,
I am very new to Access and especiall VBA. My database consists of two tables: Table1 contains unique entries in column "ID". Table2 can contain several entries for "ID". Table2 also contains a column "Name" which covers one or more IDs in column "ID".
On a form which has as the main form Table1 and a subform Table2, I am trying to do the following after adding a button:
1. On Click, open Input Box
Code:
Private Sub XXX_Click()
Dim ToDoName As String
ToDoName = InputBox("Enter name")
2. Take that name and use it in an SQL query, getting all IDs that are linked to that name in Table2.
Code:
Dim strcmd As String
strcmd = "SELECT ID FROM Table2 WHERE Name = """ & ToDoName & """"
3. Open a report using the IDs in "strcmd". Something like:
Code:
DoCmd.OpenReport "NAMEID", acViewPreview, , strWhere=strcmd
This does not work. As far as I can see, the SQL statement is not executed and nothing is passed to DoCmd.OpenReport. Any help from your side would be highly appreciated. I have to say, I cannot change the structure of the database.