Hi,
I am a little out of my element with this one:
With VBA in Excel 2010 I am connecting to a SQL server by using ODBC.
This is a two part process:
Part one:
I have created a connection string that gets me the following data: A, B, C, D, E from sheet tpoPurchOrder
Where B is equal to "1"
And
Where C is equal to a changing field under Sheets("Macros").Range("B2")
Here is part one
Part one works perfectly.
Part two is where I have problems.
Part two is a little different because I have the same connection, but what changes is the table that I am looking at "tpoPOLine" instead of "tpoPurchOrder" and the where is now going to have a variable number of commands.
I want part two to be depend on part one. Under part one I want the result from column E to be a where statement in part two.
As follows:
In particular: *E3 from Part 1*, etc.
Now my problem is that sometimes the E column from part one ends up being 1 row, sometimes it ends up being 50 rows. I would like the code to change accordingly.
My not so great solution:
1. Pull everything from the SQL server filter once in excel. This is not as efficient as the database has ~300,000 rows in the tpoPOline table and would take a lot longer then needed.
2. Create a nested if table and
Change
to the value of that nested if table
The nested if table would be something like =if(isblank(E2),"E1",if(isblank(E3)... etc for ~50 rows. I know the syntax is incorrect but you get my point.
3. Rerun the query for each value in column E. That would require the connection to happen ~50 times which would not be that great, as well as I would have to copy and paste the data after each run as the tables cannot overlap.
What I am looking for is a way to run this only once, on one sheet, without writing a nested if table with 50 if's.
Any help would be great.
Bookmarks