Aleks
asked on
ASP Syntax for IF statement
I have an IF statement, but seems like my styntax is incorrect.
The area should be displayed IF rs_qnr01 IS null (no results) or
IF rs_qnr01 is NOT null AND the field rs_qnr01("MiddleNm") = True
This is the code I have, but its behaving strange.
Any ideas ?
The area should be displayed IF rs_qnr01 IS null (no results) or
IF rs_qnr01 is NOT null AND the field rs_qnr01("MiddleNm") = True
This is the code I have, but its behaving strange.
<% ' field customized and true
if (rs_qnr01.EOF And rs_qnr01.BOF) OR ((Not rs_qnr01.EOF Or Not rs_qnr01.BOF) AND (rs_qnr01.Fields.Item("MiddleNm").Value = "True")) then
%>
Any ideas ?
If MiddleNm is a boolean then remove the quotes around "True"
ASKER
I am still getting the same error:
ADODB.Field error '800a0bcd'
Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record.
/bluedot/Questionnaire/qnr _01.asp, line 270
in this case 'rs_qnr01' is null, so it should skip the second part of the statement correct ? Its trying to run it and hence the error since 'rs_qnr01' is null, so it can't compare the field.
Can we add code so that if "MiddleNm" is null doesnt compare it ?
This is the part of the code with the issue:
(Not rs_qnr01.EOF Or Not rs_qnr01.BOF AND rs_qnr01.Fields.Item("Midd leNm").Val ue = True)
Its trying to cmpare MiddleNm when there is no rs_qnr01 recordset to begin with.
ADODB.Field error '800a0bcd'
Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record.
/bluedot/Questionnaire/qnr
in this case 'rs_qnr01' is null, so it should skip the second part of the statement correct ? Its trying to run it and hence the error since 'rs_qnr01' is null, so it can't compare the field.
Can we add code so that if "MiddleNm" is null doesnt compare it ?
This is the part of the code with the issue:
(Not rs_qnr01.EOF Or Not rs_qnr01.BOF AND rs_qnr01.Fields.Item("Midd
Its trying to cmpare MiddleNm when there is no rs_qnr01 recordset to begin with.
you need to split up the if statements, you cannot check for the existence of data returned in a record set AND for a specific column value. if no data is returned, the column won't exist.
try:
<% ' field customized and true
if not rs_qnr01.EOF And not rs_qnr01.BOF then
if rs_qnr01.Fields.Item("Midd leNm").Val ue = True then
%>
do whatever
<%
end if
end if
%>
if the field MiddleNm is a string value, then you'll need to surround True in quotes
try:
<% ' field customized and true
if not rs_qnr01.EOF And not rs_qnr01.BOF then
if rs_qnr01.Fields.Item("Midd
%>
do whatever
<%
end if
end if
%>
if the field MiddleNm is a string value, then you'll need to surround True in quotes
if (rs_qnr01.EOF And rs_qnr01.BOF) ORELSE ((Not rs_qnr01.EOF Or Not rs_qnr01.BOF) ANDALSO (rs_qnr01.Fields.Item("MiddleNm").Value = True)) then
Change it so it uses short circuiting so it does not evaluate the next part unless it needs to.
as far as I know, ORELSE is not valid classic asp syntax, but rather vb and vb.net
ASKER
I tried big monty's solution but it did not work. it should have displayed the field because rs_qnr01 IS NULL, but it did not. Here is the full code:
The code seems to be missing the first part: (rs_qnr01.EOF And rs_qnr01.BOF)
If that is the case then show the first region, forget the rest. If not then compare the value of the field, if true then show the first region if not go to the else and show the hidden field value.
<% ' middlename customized and true
if not rs_qnr01.EOF And not rs_qnr01.BOF then
if rs_qnr01.Fields.Item("MiddleNm").Value = True then
%>
<tr>
<td>Middle name</td>
<td>
<div class="col-sm-12">
<input name="MiddleNm" type="text" class="form-control" id="MiddleNm" form="form1" value="<%=(rs_contact.Fields.Item("MiddleNm").Value)%>" maxlength="30">
</div>
</td>
</tr> <% Else 'middlename hidden %>
<input name="MiddleNm" type="hidden" id="MiddleNm" value="<%=(rs_contact.Fields.Item("MiddleNm").Value)%>">
<%
end if
end if
%>
The code seems to be missing the first part: (rs_qnr01.EOF And rs_qnr01.BOF)
If that is the case then show the first region, forget the rest. If not then compare the value of the field, if true then show the first region if not go to the else and show the hidden field value.
I think I originally misunderstood you, I thought you wanted to show the field if data was being returned.
can you explain exactly what you want to happen?
can you explain exactly what you want to happen?
ASKER
Sure.
If rs_qnr01 recordset is empty display
OR if rs_qnr01 is NOT null and returns values, then check value "MiddleNm" if its true then show the above region as well.
If the value of "MiddleNm" is NOT True then show the hidden field below:
So .. the top part should show if either the recordset rs_qnr01 is null or if its not and the field value is true.
The top part should only show if rs_qnr01 is NOT null and the value of the field is false.
If rs_qnr01 recordset is empty display
<tr>
<td>Middle name</td>
<td>
<div class="col-sm-12">
<input name="MiddleNm" type="text" class="form-control" id="MiddleNm" form="form1" value="<%=(rs_contact.Fields.Item("MiddleNm").Value)%>" maxlength="30">
</div>
</td>
</tr>
OR if rs_qnr01 is NOT null and returns values, then check value "MiddleNm" if its true then show the above region as well.
If the value of "MiddleNm" is NOT True then show the hidden field below:
<input name="MiddleNm" type="hidden" id="MiddleNm" value="<%=(rs_contact.Fields.Item("MiddleNm").Value)%>">
So .. the top part should show if either the recordset rs_qnr01 is null or if its not and the field value is true.
The top part should only show if rs_qnr01 is NOT null and the value of the field is false.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks. I am starting a conference, but will check in one hour.
ASKER
Can this be done without a function ? There are like 30 fields on that one page, this would require me to do 30 functions too ?
let's see if this does what you want, then we can worry about the other fields
ASKER
ok
ASKER
Microsoft VBScript compilation error '800a0401'
Expected end of statement
/bluedot/Questionnaire/qnr _01.asp, line 278
Response.Write "<tr><td><input name='MiddleNm' type='hidden' id='MiddleNm' value='" & rs_contact.Fields.Item("Mi ddleNm").V alue) & "'></td></tr>"
Expected end of statement
/bluedot/Questionnaire/qnr
Response.Write "<tr><td><input name='MiddleNm' type='hidden' id='MiddleNm' value='" & rs_contact.Fields.Item("Mi
remove the end ) after the word Value
ASKER
Seems like this code worked. What do you think ? Simple the only problem is I have to repeat the first part of the code. not a big deal but still.
<tr>
<td>Middle name</td>
<td>
<div class="col-sm-12">
<input name="MiddleNm" type="text" class="form-control" id="MiddleNm" form="form1" value="<%=(rs_contact.Fields.Item("MiddleNm").Value)%>" maxlength="30">
</div>
</td>
</tr>
what do you mean you have to do a repeat?
ASKER
This part of the code after the first 'else' . Since I can't combine both IFs
<tr>
<td>Middle name</td>
<td>
<div class="col-sm-12">
<input name="MiddleNm" type="text" class="form-control" id="MiddleNm" form="form1" value="<%=(rs_contact.Fields.Item("MiddleNm").Value)%>" maxlength="30">
</div>
</td>
</tr>
ASKER
The code I posted last works, so I will just go with that.
ASKER
Closest solution
sorry I didnt get back to you sooner, that whole job thing sometimes gets in the way :)
glad you got the solution you needed!
glad you got the solution you needed!