P
philip260
Hello All.
I have written a module which runs an access query and then stores
the result of the query in variables and at the end of the module I
assign those variables to a particular cell in excel. The variables
are set in a Do Until loop on an access query. What i want to be able
to do is minimize the code that i have to use and put in place a
better loop code to eliminiate the programming text redundancy. I want
the variables to be set to query results with certain parameters. I
know theres a better way to do what im doing but im new to writing vb.
Please see code below.
Do Until rst.EOF
If rst.Fields(0) Like "NBMONEY*" And rst.Fields(1) Like "APPWCASH"
And rst.Fields(2) Like "5:00:00 AM*" Then
nbmoneyappwcash5am = rst.Fields(3)
ElseIf rst.Fields(0) Like "NBMONEY*" And rst.Fields(1) Like
"APPWCASH" And rst.Fields(2) Like "6:00:00 AM*" Then
nbmoneyappwcash6am = rst.Fields(3)
ElseIf rst.Fields(0) Like "NBMONEY*" And rst.Fields(1) Like
"APPWCASH" And rst.Fields(2) Like "7:00:00 AM*" Then
nbmoneyappwcash7am = rst.Fields(3)
ElseIf rst.Fields(0) Like "NBMONEY*" And rst.Fields(1) Like
"APPWCASH" And rst.Fields(2) Like "8:00:00 AM*" Then
nbmoneyappwcash8am = rst.Fields(3)
ElseIf rst.Fields(0) Like "NBMONEY*" And rst.Fields(1) Like
"APPWCASH" And rst.Fields(2) Like "9:00:00 AM*" Then
nbmoneyappwcash9am = rst.Fields(3)
ElseIf rst.Fields(0) Like "NBMONEY*" And rst.Fields(1) Like
"APPWCASH" And rst.Fields(2) Like "10:00:00 AM*" Then
nbmoneyappwcash10am = rst.Fields(3)
ElseIf rst.Fields(0) Like "NBMONEY*" And rst.Fields(1) Like
"APPWCASH" And rst.Fields(2) Like "11:00:00 AM*" Then
nbmoneyappwcash11am = rst.Fields(3)
ElseIf rst.Fields(0) Like "NBMONEY*" And rst.Fields(1) Like
"APPWCASH" And rst.Fields(2) Like "12:00:00 PM*" Then
nbmoneyappwcash12pm = rst.Fields(3)
ElseIf rst.Fields(0) Like "NBMONEY*" And rst.Fields(1) Like
"APPWCASH" And rst.Fields(2) Like "1:00:00 PM*" Then
nbmoneyappwcash1pm = rst.Fields(3)
ElseIf rst.Fields(0) Like "NBMONEY*" And rst.Fields(1) Like
"APPWCASH" And rst.Fields(2) Like "2:00:00 PM*" Then
nbmoneyappwcash2pm = rst.Fields(3)
ElseIf rst.Fields(0) Like "NBMONEY*" And rst.Fields(1) Like
"APPWCASH" And rst.Fields(2) Like "3:00:00 PM*" Then
nbmoneyappwcash3pm = rst.Fields(3)
ElseIf rst.Fields(0) Like "NBMONEY*" And rst.Fields(1) Like
"APPWCASH" And rst.Fields(2) Like "4:00:00 PM*" Then
nbmoneyappwcash4pm = rst.Fields(3)
ElseIf rst.Fields(0) Like "NBMONEY*" And rst.Fields(1) Like
"APPWCASH" And rst.Fields(2) Like "5:00:00 PM*" Then
nbmoneyappwcash5pm = rst.Fields(3)
ElseIf rst.Fields(0) Like "NBMONEY*" And rst.Fields(1) Like
"APPWCASH" And rst.Fields(2) Like "6:00:00 PM*" Then
nbmoneyappwcash6pm = rst.Fields(3)
ElseIf rst.Fields(0) Like "NBMONEY*" And rst.Fields(1) Like
"APPWCASH" And rst.Fields(2) Like "7:00:00 PM*" Then
nbmoneyappwcash7pm = rst.Fields(3)
ElseIf rst.Fields(0) Like "NBMONEY*" And rst.Fields(1) Like
"MONEYIN" And rst.Fields(2) Like "5:00:00 AM*" Then
nbmoneymoneyin5am = rst.Fields(3)
ElseIf rst.Fields(0) Like "NBMONEY*" And rst.Fields(1) Like
"MONEYIN" And rst.Fields(2) Like "6:00:00 AM*" Then
nbmoneymoneyin6am = rst.Fields(3)
ElseIf rst.Fields(0) Like "NBMONEY*" And rst.Fields(1) Like
"MONEYIN" And rst.Fields(2) Like "7:00:00 AM*" Then
nbmoneymoneyin7am = rst.Fields(3)
ElseIf rst.Fields(0) Like "NBMONEY*" And rst.Fields(1) Like
"MONEYIN" And rst.Fields(2) Like "8:00:00 AM*" Then
nbmoneymoneyin8am = rst.Fields(3)
ElseIf rst.Fields(0) Like "NBMONEY*" And rst.Fields(1) Like
"MONEYIN" And rst.Fields(2) Like "9:00:00 AM*" Then
nbmoneymoneyin9am = rst.Fields(3)
ElseIf rst.Fields(0) Like "NBMONEY*" And rst.Fields(1) Like
"MONEYIN" And rst.Fields(2) Like "10:00:00 AM*" Then
nbmoneymoneyin10am = rst.Fields(3)
ElseIf rst.Fields(0) Like "NBMONEY*" And rst.Fields(1) Like
"MONEYIN" And rst.Fields(2) Like "11:00:00 AM*" Then
nbmoneymoneyin11am = rst.Fields(3)
ElseIf rst.Fields(0) Like "NBMONEY*" And rst.Fields(1) Like
"MONEYIN" And rst.Fields(2) Like "12:00:00 PM*" Then
nbmoneymoneyin12pm = rst.Fields(3)
ElseIf rst.Fields(0) Like "NBMONEY*" And rst.Fields(1) Like
"MONEYIN" And rst.Fields(2) Like "1:00:00 PM*" Then
nbmoneymoneyin1pm = rst.Fields(3)
ElseIf rst.Fields(0) Like "NBMONEY*" And rst.Fields(1) Like
"MONEYIN" And rst.Fields(2) Like "2:00:00 PM*" Then
nbmoneymoneyin2pm = rst.Fields(3)
ElseIf rst.Fields(0) Like "NBMONEY*" And rst.Fields(1) Like
"MONEYIN" And rst.Fields(2) Like "3:00:00 PM*" Then
nbmoneymoneyin3pm = rst.Fields(3)
ElseIf rst.Fields(0) Like "NBMONEY*" And rst.Fields(1) Like
"MONEYIN" And rst.Fields(2) Like "4:00:00 PM*" Then
nbmoneymoneyin4pm = rst.Fields(3)
ElseIf rst.Fields(0) Like "NBMONEY*" And rst.Fields(1) Like
"MONEYIN" And rst.Fields(2) Like "5:00:00 PM*" Then
nbmoneymoneyin5pm = rst.Fields(3)
ElseIf rst.Fields(0) Like "NBMONEY*" And rst.Fields(1) Like
"MONEYIN" And rst.Fields(2) Like "6:00:00 PM*" Then
nbmoneymoneyin6pm = rst.Fields(3)
ElseIf rst.Fields(0) Like "NBMONEY*" And rst.Fields(1) Like
"MONEYIN" And rst.Fields(2) Like "7:00:00 PM*" Then
nbmoneymoneyin7pm = rst.Fields(3)
Any help would be appreciated!
Thanks in advance
Phil
I have written a module which runs an access query and then stores
the result of the query in variables and at the end of the module I
assign those variables to a particular cell in excel. The variables
are set in a Do Until loop on an access query. What i want to be able
to do is minimize the code that i have to use and put in place a
better loop code to eliminiate the programming text redundancy. I want
the variables to be set to query results with certain parameters. I
know theres a better way to do what im doing but im new to writing vb.
Please see code below.
Do Until rst.EOF
If rst.Fields(0) Like "NBMONEY*" And rst.Fields(1) Like "APPWCASH"
And rst.Fields(2) Like "5:00:00 AM*" Then
nbmoneyappwcash5am = rst.Fields(3)
ElseIf rst.Fields(0) Like "NBMONEY*" And rst.Fields(1) Like
"APPWCASH" And rst.Fields(2) Like "6:00:00 AM*" Then
nbmoneyappwcash6am = rst.Fields(3)
ElseIf rst.Fields(0) Like "NBMONEY*" And rst.Fields(1) Like
"APPWCASH" And rst.Fields(2) Like "7:00:00 AM*" Then
nbmoneyappwcash7am = rst.Fields(3)
ElseIf rst.Fields(0) Like "NBMONEY*" And rst.Fields(1) Like
"APPWCASH" And rst.Fields(2) Like "8:00:00 AM*" Then
nbmoneyappwcash8am = rst.Fields(3)
ElseIf rst.Fields(0) Like "NBMONEY*" And rst.Fields(1) Like
"APPWCASH" And rst.Fields(2) Like "9:00:00 AM*" Then
nbmoneyappwcash9am = rst.Fields(3)
ElseIf rst.Fields(0) Like "NBMONEY*" And rst.Fields(1) Like
"APPWCASH" And rst.Fields(2) Like "10:00:00 AM*" Then
nbmoneyappwcash10am = rst.Fields(3)
ElseIf rst.Fields(0) Like "NBMONEY*" And rst.Fields(1) Like
"APPWCASH" And rst.Fields(2) Like "11:00:00 AM*" Then
nbmoneyappwcash11am = rst.Fields(3)
ElseIf rst.Fields(0) Like "NBMONEY*" And rst.Fields(1) Like
"APPWCASH" And rst.Fields(2) Like "12:00:00 PM*" Then
nbmoneyappwcash12pm = rst.Fields(3)
ElseIf rst.Fields(0) Like "NBMONEY*" And rst.Fields(1) Like
"APPWCASH" And rst.Fields(2) Like "1:00:00 PM*" Then
nbmoneyappwcash1pm = rst.Fields(3)
ElseIf rst.Fields(0) Like "NBMONEY*" And rst.Fields(1) Like
"APPWCASH" And rst.Fields(2) Like "2:00:00 PM*" Then
nbmoneyappwcash2pm = rst.Fields(3)
ElseIf rst.Fields(0) Like "NBMONEY*" And rst.Fields(1) Like
"APPWCASH" And rst.Fields(2) Like "3:00:00 PM*" Then
nbmoneyappwcash3pm = rst.Fields(3)
ElseIf rst.Fields(0) Like "NBMONEY*" And rst.Fields(1) Like
"APPWCASH" And rst.Fields(2) Like "4:00:00 PM*" Then
nbmoneyappwcash4pm = rst.Fields(3)
ElseIf rst.Fields(0) Like "NBMONEY*" And rst.Fields(1) Like
"APPWCASH" And rst.Fields(2) Like "5:00:00 PM*" Then
nbmoneyappwcash5pm = rst.Fields(3)
ElseIf rst.Fields(0) Like "NBMONEY*" And rst.Fields(1) Like
"APPWCASH" And rst.Fields(2) Like "6:00:00 PM*" Then
nbmoneyappwcash6pm = rst.Fields(3)
ElseIf rst.Fields(0) Like "NBMONEY*" And rst.Fields(1) Like
"APPWCASH" And rst.Fields(2) Like "7:00:00 PM*" Then
nbmoneyappwcash7pm = rst.Fields(3)
ElseIf rst.Fields(0) Like "NBMONEY*" And rst.Fields(1) Like
"MONEYIN" And rst.Fields(2) Like "5:00:00 AM*" Then
nbmoneymoneyin5am = rst.Fields(3)
ElseIf rst.Fields(0) Like "NBMONEY*" And rst.Fields(1) Like
"MONEYIN" And rst.Fields(2) Like "6:00:00 AM*" Then
nbmoneymoneyin6am = rst.Fields(3)
ElseIf rst.Fields(0) Like "NBMONEY*" And rst.Fields(1) Like
"MONEYIN" And rst.Fields(2) Like "7:00:00 AM*" Then
nbmoneymoneyin7am = rst.Fields(3)
ElseIf rst.Fields(0) Like "NBMONEY*" And rst.Fields(1) Like
"MONEYIN" And rst.Fields(2) Like "8:00:00 AM*" Then
nbmoneymoneyin8am = rst.Fields(3)
ElseIf rst.Fields(0) Like "NBMONEY*" And rst.Fields(1) Like
"MONEYIN" And rst.Fields(2) Like "9:00:00 AM*" Then
nbmoneymoneyin9am = rst.Fields(3)
ElseIf rst.Fields(0) Like "NBMONEY*" And rst.Fields(1) Like
"MONEYIN" And rst.Fields(2) Like "10:00:00 AM*" Then
nbmoneymoneyin10am = rst.Fields(3)
ElseIf rst.Fields(0) Like "NBMONEY*" And rst.Fields(1) Like
"MONEYIN" And rst.Fields(2) Like "11:00:00 AM*" Then
nbmoneymoneyin11am = rst.Fields(3)
ElseIf rst.Fields(0) Like "NBMONEY*" And rst.Fields(1) Like
"MONEYIN" And rst.Fields(2) Like "12:00:00 PM*" Then
nbmoneymoneyin12pm = rst.Fields(3)
ElseIf rst.Fields(0) Like "NBMONEY*" And rst.Fields(1) Like
"MONEYIN" And rst.Fields(2) Like "1:00:00 PM*" Then
nbmoneymoneyin1pm = rst.Fields(3)
ElseIf rst.Fields(0) Like "NBMONEY*" And rst.Fields(1) Like
"MONEYIN" And rst.Fields(2) Like "2:00:00 PM*" Then
nbmoneymoneyin2pm = rst.Fields(3)
ElseIf rst.Fields(0) Like "NBMONEY*" And rst.Fields(1) Like
"MONEYIN" And rst.Fields(2) Like "3:00:00 PM*" Then
nbmoneymoneyin3pm = rst.Fields(3)
ElseIf rst.Fields(0) Like "NBMONEY*" And rst.Fields(1) Like
"MONEYIN" And rst.Fields(2) Like "4:00:00 PM*" Then
nbmoneymoneyin4pm = rst.Fields(3)
ElseIf rst.Fields(0) Like "NBMONEY*" And rst.Fields(1) Like
"MONEYIN" And rst.Fields(2) Like "5:00:00 PM*" Then
nbmoneymoneyin5pm = rst.Fields(3)
ElseIf rst.Fields(0) Like "NBMONEY*" And rst.Fields(1) Like
"MONEYIN" And rst.Fields(2) Like "6:00:00 PM*" Then
nbmoneymoneyin6pm = rst.Fields(3)
ElseIf rst.Fields(0) Like "NBMONEY*" And rst.Fields(1) Like
"MONEYIN" And rst.Fields(2) Like "7:00:00 PM*" Then
nbmoneymoneyin7pm = rst.Fields(3)
Any help would be appreciated!
Thanks in advance
Phil