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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Request.form with null values

Status
Not open for further replies.

VBAHole22

Programmer
Nov 7, 2002
41
US
I am writing an ASP page to take the results of a user survey and enter them into a new record in an access db. It works fine when the user fills out all of the questions (some yes/no, some multiple choice) but if they leave one blank the page returns an error at the line where the db would be updated. So say if question 4 is left blank it chokes on the following line:

rstSurvey("Q4") = Q4

which is the statement that updates the db. Yet it doesn't mind that I say, earlier on:

Q4 = Request.Form("Q4")

Where should I be testing for nulls and how. If a question is left null I don't want anything sent to the db.

Thanks for any help
 
q4 = "'" & request.form("q4") & "'"
if q4 = "''" then q4 = "null"
rstSurvey("Q4") = Q4



Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

fart.gif
 
Okay, I think that is going to work with my text fields. But now I have yes/no fields that I need to deal with. I hate the yes/no data type in Access! Because there is no third state for 'no answer' (right?). So I changed it to an integer field but then yes=1 and no=0 so what do you do with the no answer responses.

I do appreciate your help with this.
 
I think I am just going to go with a text field with "yes", "no" and "null" and have null be the default.
 
Well, you'll need to decide what the default needs to be. I would then make the form show the default value and force the user to switch it where relevant.

Even better, write a script that forces a chice prior to submission of the form.

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

fart.gif
 
It sounds like you want all the questions answered before the user can submit the survey. In this case you would check each form variable for a value. I'm assuming your yes/no questions actually have 2 radio buttons -- one for yes and one for no.

You have a couple of options to check for null values, see post above by mwolf00 for one option.

Here are two others:

The 'myerr' variable is passed back so you know which question was not answered and you can tell the user specifically which answer he/she left blank.

q4 = request.form("q4")
'The isnull function works most of the time, but it can be picky.
if isnull(q4) then
response.redirect "surveypage.asp?myerr=4"
end if

I use the following option because I have found it is the most accurate:

q4 = request.form("q4")
'here we check for the length of the variable if there is no value the length will be 0, thus a no answer.

if len(q4)=0 then
response.redirect "surveypage.asp?myerr=4"
end if

Hope this helps,

Tom
 
I want the user to have the option of opting out of answering any questions they don't want to.
So I changed the data type of the Yes/No field to text, changed the Post values of the radio buttons to "Yes" and "No" and Voila. ASP no longer cares that they are null and it will still update the table with the values that are present, without any testing for nulls. Of course now I have blank cells in my db instead of the word "null", but that's alright.

So is ASP only finicky about nulls for number fields and yes/no fields but not text?
 
asp is not picky about them - your database is...

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

fart.gif
 
True

With access on the backend, you'll need to make sure that all of your text fields allow null values as well. If not, you will get an error message when submitting a null value. For yes/no fields, you need to send the values of 0(no) or
-1(yes). Yes/No fields are funny -- when you write a query in asp to check the value of the field, you can use field = No or Field = Yes, but to insert a value you have to send over 0/-1. Not sure why, but that's been my experience.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top