Math with Variables

islu0102

Registered User.
Local time
Today, 12:11
Joined
Aug 19, 2009
Messages
23
I am attempting to piece together my first true VBA project, but I have hit a snag. I have entered the following code into the immediate window:

Code:
dim sCnt as Integer    
dim wCnt as Integer
dim suDif as Integer
sCnt = DLookup("[Number_of_Su]", "Su_Profile", "[Su_Num] = 9")
wtCnt = IIf(DCount("*", "WorkTable1", "Su_Num = 9") = "", 0, DCount("*", "WorkTable1", "Su_Num = 9"))
suDif = sCnt - wtCnt
msgbox suDif

'msgbox wtCnt' returns a 0, which is what I wanted it to return. 'msgbox sCnt' returns an 8, which is also what I was looking for.

My question is why does 'msgbox suDif' return a null value? Shouldn't it return an 8? :confused:

Thanks in advance for any help you can give.
 
I'm not sure that will work in the Immediate window; try behind a button or something (I tested and it worked behind a button but not in the Immediate window). I'd point out that you declared wCnt but used wtCnt.

Edit: I suspect when run from the Immediate window you're getting the "result" from the message box, not the value of the variable.
 
oops. wCnt instead of wtCnt was a typo in this thread, but thank you for pointing it out! :) I'll try to test this behind a button. Thanks for the tip. :)
 

Users who are viewing this thread

Back
Top Bottom