0

I'm pulling a field from a table and doing different things depending on what the result is. Here's my code

<%stringA ="Select field From table Where something=1"
set response = connFW.Execute(stringA )
set result = response ("field")
If result ="y" Then 
Response.Write("The field is: " & result )
End If%>

It outputs this:

The field is: y

Then, later, I have an If statement:

<% ElseIf result ="y"  or Session("customer_id") <> "" Then
Do Something
%>

But it never executes what's in the ElseIf statement! It says right at the top of the page that it gave the correct result! Am I missing something?

Note: To avoid confusion, this code is at the top of the page:

Set connFW = Server.CreateObject("ADODB.Connection")
connFW.ConnectionTimeout = Application("FW_ConnectionTimeout")
connFW.CommandTimeout = Application("FW_CommandTimeout")
connFW.Open Application("FW_ConnectionString")
1
  • If you have ElseIf with condition result="y" which is satisfied in first If how will the control come to this line. So better have just Session("consumer_id") <> "" in ElseIf or put it inside If block. Commented Sep 4, 2012 at 11:29

2 Answers 2

1

Without seeing your complete code, it's hard to see where the exact problem is, but I see two possibilities. Either you have an "ElseIf" on its own, in which case you should change ElseIf to just plain If:

If result ="y" or Session("customer_id") <> "" Then

...or you are placing your ElseIf after your previous one:

If result ="y" Then 
    Response.Write("The field is: " & result )
ElseIf result ="y" or Session("customer_id") <> "" Then  
    Do Something
End If

If it's the latter, then your ElseIf will not execute because the result = "y" condition has already been met in the previous If-statement.

Sign up to request clarification or add additional context in comments.

Comments

1

Your ElseIf statement does not appear to have a preceding If statement, unless you're leaving out some code somewhere.

You need:

If x Then
  Do something
ElseIf y Then
  Do something else
End If

You can't have ElseIf just sitting off on it's own.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.