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

handling empty values in a form

Status
Not open for further replies.

mangocinn

Programmer
Jul 26, 2001
66
US
I have a somewhat simple question.

I have a select box in a form and the selection will then be sent to a function that adds a record in a sql db. The field that I'm adding the data to is an integer field. Here's the situation. If the user does not choose a selection...hence select1 = "" then I get a message saying:

ADODB.Command error '800a0d5d'

Application uses a value of the wrong type for the current operation

On the other hand. If I actually set the selection to null in the code then send it to the function that is adding the record in the db, it all works fine.

If select1 = "" then
select1 = null
end if


Well, being that there are many other fields in the form,
it seems inefficient to check all the fields for emptiness and set it to null. Is there some other way of dealing w/ this situation?

Thanks in advance.
 
No, this is the standard way. You could conversely, set a default selection for the user and never have to worry about checking if it is empty.

Probably the easiest solution is to write a short method that takes a parameter name and returns the value from the Request object or null if it is empty.

Example:
Code:
Function parseParameter(String paramName)
  if Request(paramName) = "" then
     parseParameter = null
  else
     parseParameter = Request(paramName)
  end if
end Function
Wushutwist
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top