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

ASP and Access: Combo boxes

Status
Not open for further replies.

YoelBenYossef

Programmer
Nov 16, 2005
38
CA
Hi there,
I'm currently writing a program that uses ASP to request information and put it into an Access DB.

The problem arises when I use the checkboxes. The access fields are boolean yes/no fields. When I use:

rst("JobEmail")=request.form("chkEmail")

it works perfectly if the checkbox is checked, since the value for the checkbox is true. The problem is that if the box is unchecked, it inserts a blank space, and I get an error.

Is there any way to fix this in a single step? I'd rather avoid using if-then-else.

Thanks
Eric
 
One possibility is to create a small function that would assign a value regardless of whether the box is checked or not. It could also be used in multiple instances should you have other checkboxes that you would need to verify. Using psuedo-code it would be something like (you'll need to properly code and debug this, of course):
Code:
function getValue(testValue)
  if testValue = "" then
    getValue = "No"
  else
    getValue = "Yes"
  end if
end function

[COLOR=green]'Now we use the function.[/color]
rst("JobEmail")=[COLOR=red]getValue([/color]request.form("chkEmail")[COLOR=red])[/color]

------------------------------------------------------------------------------------------------------------------------
"Men occasionally stumble over the truth, but most of them pick themselves up and hurry off as if nothing ever happened."
- Winston Churchill
 
The specification for HTML forms does not provide for sending any value when a checkbox is unchecked.

So you will get some characters if it was checked, and nothing if it is not.

But ASP doesnt throw an error if your check for something in the Request collection that is not there... you get an empty string back.

So you can use this to your advantage:
[tt]
TheValue = Len(Request.Form("chkEmail")) > 0[/tt]

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top