crystalball
New Member
- Joined
- Aug 15, 2011
- Messages
- 11
Hello,
I have a query I created in an Access DB. It functions as intended when I run it in access, whether I'm using hard coded data in my WHERE clause or prompt the user, but now I have to figure out how to pass the variables I want from an excel spreadsheet.
If I run the query that's already set up in access from excel and the data is hardcoded it works. But that won't let me change the variables in excel like I want. If I try to send the SQL straight from excel to the table it doesn't run even if I change nothing between access and excel. It seems to be hung up on the WHERE statement (if I remove it the query will run, just choosing from all rows in the table).
I've tried to resolve this on my own, attempting to use a linked sheet in access to get the data in there and run the saved access query, but it doesn't seem to let me select the query in excel once I start using that data. Attempting to force it anyway failed.
I'm trying to make that query pull data from two cells ("Sheet1!A2 and Sheet1!A4) and return 5 random results from Column3.
The Query (I'm not actually using Sheet1!A2 and Sheet1!A4 in this, my last attempt tried to pull the data from a linked sheet. But it's there to keep the logic clear):
Can anyone help me sort this out? I'd appreciate it.
PS - The how of this is open to change. If there's a way to get 5 random column3s where column1=x and column2=y, even if it requires weird jury rigging or pulling the whole table into excel first then doing some work on it, I'm open to that. But I need something where the user will never need to open access, the UI must be entirely excel.
I have a query I created in an Access DB. It functions as intended when I run it in access, whether I'm using hard coded data in my WHERE clause or prompt the user, but now I have to figure out how to pass the variables I want from an excel spreadsheet.
If I run the query that's already set up in access from excel and the data is hardcoded it works. But that won't let me change the variables in excel like I want. If I try to send the SQL straight from excel to the table it doesn't run even if I change nothing between access and excel. It seems to be hung up on the WHERE statement (if I remove it the query will run, just choosing from all rows in the table).
I've tried to resolve this on my own, attempting to use a linked sheet in access to get the data in there and run the saved access query, but it doesn't seem to let me select the query in excel once I start using that data. Attempting to force it anyway failed.
I'm trying to make that query pull data from two cells ("Sheet1!A2 and Sheet1!A4) and return 5 random results from Column3.
The Query (I'm not actually using Sheet1!A2 and Sheet1!A4 in this, my last attempt tried to pull the data from a linked sheet. But it's there to keep the logic clear):
SELECT TOP 5 Column3
FROM DB
WHERE ((DB.Column1)= (Sheet1!A2))
And ((DB.Column2)= (Sheet1!A4))
ORDER BY RND(Unique ID);
Can anyone help me sort this out? I'd appreciate it.
PS - The how of this is open to change. If there's a way to get 5 random column3s where column1=x and column2=y, even if it requires weird jury rigging or pulling the whole table into excel first then doing some work on it, I'm open to that. But I need something where the user will never need to open access, the UI must be entirely excel.
Last edited: