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!

Passing checkbox value to Access 2k back end 2

Status
Not open for further replies.

cruford

Programmer
Dec 6, 2002
138
US
I have this code to update my DB records:


ElseIf Len(Request.Form("cmdUpdate")) > 0 Then
'Update record
If Request.Form("chkFloppy") = "on" Then
strFloppy = "yes"
Else
strFloppy = "no"
End If
If Request.Form("chkNIC") = "on" Then
strNIC = "yes"
Else
strNIC = "no"
End If
If Request.Form("chkCDRom") = "on" Then
strCD = "yes"
Else
strCD = "no"
End If
If Request.Form("chkBurner") = "on" Then
strBurner = "yes"
Else
strBurner = "no"
End If
If Request.Form("chkModem") = "on" Then
strModem = "yes"
Else
strModem = "no"
End If
strSQL = "UPDATE tblComputers SET Status='" & Request.Form("cboStatus") & "', Department='" & Request.Form("txtDept") & _
"', Cube='" & Request.Form("txtCube") & "', FirstName='" & Request.Form("txtFirstName") & "', LastName='" & Request.Form("txtLastName") & _
"', CarePak='" & Request.Form("txtCarePak") & "', Vendor='" & Request.Form("cboVendor") & "', Model='" & Request.Form("txtModel") & _
"', Processor='" & Request.Form("txtProc") & "', ClockSpeed=" & Request.Form("txtSpeed") & ", BIOS='" & Request.Form("txtBIOS") & _
"', RAM=" & Request.Form("txtRAM") & ", HardDrive=" & Request.Form("txtHD") & ", VideoCard='" & Request.Form("txtVideo") & "', Modem='" & strModem & _
"'
, VideoCardMemory=" & Request.Form("txtVidMem") & ", MouseManufacturer='" & Request.Form("txtMouse") & "', Hub='" & Request.Form("txtHub") & "', Port='" & Request.Form("txtPort") & _
"', IPAddress='" & Request.Form("txtIP") & "', HostName='" & Request.Form("cboHostName") & "', OperatingSystem='" & Request.Form("cboOS") & _
"', OfficeApplication='" & Request.Form("cboOffApp") & "', PurchaseDate='" & Request.Form("txtPurchDate") & "', PurchasePrice='" & Request.Form("txtPurchPrice") & _
"', Notes='" & Request.Form("txtNotes") & "' WHERE SerialNumber='" & Request.Form("txtSerialNum") & "'"
strDSN = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\INetPub\ Response.Write strSQL 'Debugging to check SQL syntax
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open strDSN
Conn.Execute strSQL,numRecords,1
If numRecords > 0 Then
Response.Write &quot;<H1>Record Updated</H1>&quot;
Else
Response.Write &quot;<H1>Error Updating Record</H1>&quot;
End If
Conn.Close
Set Conn = Nothing


The little section is blue is a &quot;Yes/No&quot; data field in my Access 2000 database. If I take the check boxes part out it updates the record, as soon as I put it back in it tells me SYNTAX error in SQL statement. Anyone have any work arounds for this?
 
probably because a checkbox only passes its value when checked. if unchecked, your sql is going to look like

...value, Modem=, VideoCardMemory=value, MouseManufacturer=value,...

i would suggest yes/no radio buttons or select list with yes/no options.

=========================================================
while (!succeed) try();
-jeff
 
I think that Access stores Yes values as -1 and No values as 0. Try substituting -1 and 0 for &quot;yes&quot; and &quot;no&quot;.

SteveDi
 
Jemm thanks for the response. I went and added:

Response.Write strSQL & &quot;<BR><BR>&quot;'Debugging to check SQL syntax
Response.Write strModem & &quot;<BR>&quot;
Response.Write strNIC & &quot;<BR>&quot;
Response.Write strCD & &quot;<BR>&quot;
Response.Write strBurner & &quot;<BR>&quot;
Response.Write strFloppy & &quot;<BR>&quot;

The values coming back are &quot;yes&quot; and &quot;no&quot; if its checked or not checked respectively. The SQL statement also looks correct. Here is the sample output from above:

UPDATE tblComputers SET Status='Active', Department='AR', Cube='G025', FirstName='Some', LastName='Person', CarePak='', Vendor='Gateway', Model='GP6-400C', Processor='Intel Celeron', ClockSpeed=400, BIOS='', CDROM='yes', CDBurner='no', RAM=128, HardDrive=4, VideoCard='Built-in ATI AGP', Modem='no', NetworkCard='yes', ADrive='yes', VideoCardMemory=8, MouseManufacturer='Microsoft', Hub='', Port='', IPAddress='DHCP', HostName='sperson', OperatingSystem='Windows 98', OfficeApplication='Office 2000 Small Business', PurchaseDate='07/13/1999', PurchasePrice='$881.00', Notes='' WHERE SerialNumber='0123456789'

Modem: no
NIC: yes
CDROM: yes
CD Burner: no
Floppy Drive: yes

Any other ideas?
 
Stevedi,

That worked perfect thanks. Thanks for both the responses.
 
try using numeric values as stevedi has suggested, or try using true/false instead of 'yes'/'no'. BDC.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top