VBA While loop using an SQL statement as my While
I'm writing some code behind some spreadsheets and I need to loop through some code, like getting data from a database doing some formulas and moving the data to a new sheet. My code for getting the data from the database is getting all of the values in multiple columns where the data has not been reported and has the same file name ( the data is coming from a file ), I have a field which states whether or not it has be reported by a simple "Y" or "N", and a field which holds the filename it came from.
So I need a while that, "WHILE" there's data that hasn't been reported do the rest of my code ( this includes my first SQL statement I said as this get data that hasn't been reported from each individual filename ).
I've been trying to get this to work for days but just have not been able to figure out how, so any help would be very grateful.
Update:
Database has a entity called datareported, can either be "N" or "Y", and also datadatfile which is the name from which the data came from.
So,
WHILE datareported = 'N' THEN
"SELECT (the data rows I want)
FROM tbldata
WHERE datareported='N' and datadatfile =
(SELECT min(datadatfile)
FROM tbldata WHERE datareported='N')"
This means that I loop through the rest of my code WHILE there is data that hasn't been reported and only bring in data of the same name ( from datadatfile ) so that the code can be run on that data.
That's basically what I want to do and that'开发者_Go百科s pretty much what I have tried. I have tried a few other things and normally get a return of type mis-match.
Cheers,
Sam
More information needed for a solution but this may be of some help to push you in the right direction...
'ws1 = worksheet object...
bC = true
cnt1 = 2 ' starting row
Do While bC
If ws1.cells(cnt1, 1) = "N" Then
'Run your SQL here
Else
'Already reported...
End If
cnt1 = cnt1 + 1
If 'you hit the last row on your worksheet set bC = False to exit loop
Loop
Missed the update...this wont help, sorry.
精彩评论