Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting a Variable based on If Then statement 1

Status
Not open for further replies.

kab555

Programmer
Jan 18, 2002
46
US
Hi,
I am “teaching” myself VB (version 6). I am trying to pass a value to a variable based on an If Then ElseIf statement. The problem is that only the 1st part of the statement works. That is, if the value fits the first part of the statement, then the program works fine, but if the value does not fit the first part (therefore should fit the ElseIf section) then the program hangs. Am I doing something wrong?? Below is the piece of code that I’m dealing with.

If txtPolicy <> &quot;&quot; Then
StrPolicySelectFormula = &quot;{KB_CLAIM_POLICY_AMT_VIEW.POLNO}= '&quot; & txtPolicy & &quot;'&quot;
ElseIf txtPolicy = &quot;&quot; Then
StrPolicySelectFormula = &quot;{KB_CLAIM_POLICY_AMT_VIEW.POLNO}= {KB_CLAIM_POLICY_AMT_VIEW.POLNO}&quot;
Exit Sub
End If

I've switched the sections around, and still the program will only work if the value fits the 1st part of the statement.
 
Hi,
Don't use the ElseIf, instead use Else

If txtPolicy <> &quot;&quot; Then
StrPolicySelectFormula = &quot;{KB_CLAIM_POLICY_AMT_VIEW.POLNO}= '&quot; & txtPolicy & &quot;'&quot;
Else
StrPolicySelectFormula = &quot;{KB_CLAIM_POLICY_AMT_VIEW.POLNO}= {KB_CLAIM_POLICY_AMT_VIEW.POLNO}&quot;
Exit Sub
End If

It's either one or the other, right?

Jon
 
Yup, it's either one or the other! The program works now, thank you very much!!

And to think, I've been struggling with this for hours!!!! That's one gold star for you, and a smack upside the head for me.....

Kristie
 
I'm still left wondering about the academic question of why the elseif didn't work... The only suggestion I can make is that the txtPolicy variable contained a NULL.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top