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

quick question about checkboxes

Status
Not open for further replies.

jakeir

Programmer
Apr 7, 2009
25
US
Hi,
I have a check box on a form, as part of some fields that take in user info. Then in my code behind the form inserts the data from the form fields to a SQL server table. Thsi all works fine. The problem is that currently I have to ask the use to clik on the check box to get it to enable I guess. because if they don't, even though I have set it to enabe and have it checked, it will error out. Any Ideas will be helpful.
Thank you

 
Hi Duane,
Sorry, that I have not been able to get back to this sooner, but the error message a type miss match error, that is all it says. This is not web related at all, it is an Ms Access form connection through an ADO connection string to a SQL Server 2005 database.
ANd again the code works great if I have the use check and uncheck the checkbox.
here is my code:

'Set Declarations
Dim Rs As ADODB.Recordset
Dim Rs1 As ADODB.Recordset
Dim RsIns As ADODB.Recordset
Dim RsCnt As ADODB.Recordset
Dim RsCntAfterIns As ADODB.Recordset
Dim RsCombo As ADODB.Recordset
Dim cnt1, cnt2 As Integer


'Set Objects
Set RsIns = New ADODB.Recordset
Set RsCnt = New ADODB.Recordset
Set RsCntAfterIns = New ADODB.Recordset
Set RsCombo = New ADODB.Recordset

sqlCnt = "Select Count(*) As Rcnt From Managers "

'Set recordset Properties
With RsCnt
.CursorLocation = adUseClient
.CursorType = adOpenStatic
.ActiveConnection = cn2
.LockType = adLockOptimistic
.Open sqlCnt
End With

cnt1 = RsCnt!Rcnt

sqlIns = "Select * From Managers Where [Mgr_Last_Name] = '" & txtMgr_Last_Name & "' And [Mgr_First_Name]= '" & txtMgr_First_Name & "' And [Plan] = '" & cboLocation & "'"

'Set recordset Properties
With RsIns
.CursorLocation = adUseClient
.CursorType = adOpenStatic
.ActiveConnection = cn2
.LockType = adLockOptimistic
.Open sqlIns
End With

If RsIns.RecordCount = 0 Then
DoCmd.SetWarnings (WarningsOff)
StrSql1 = "INSERT INTO Managers([Mgr_Last_Name], [Mgr_First_Name], [Mgr_Is_VP], [Vice President], [Plan]) Values('" & txtMgr_Last_Name & "', '" & txtMgr_First_Name & "', '" & chkMgr_Is_VP & "','" & txtVP & "','" & cboLocation & "')"
DoCmd.RunSQL StrSql1
Else
MsgBox ("The person you entered is already in the database.")
txtMgr_Last_Name.SetFocus
cn2.Close
Exit Sub
End If

cn2.Close
 
If Mgr_Is_VP is a yes/no or numeric field then remove the quotes:
Code:
   StrSql1 = "INSERT INTO Managers([Mgr_Last_Name], [Mgr_First_Name], " & _
    "[Mgr_Is_VP], [Vice President], [Plan]) " & _
    " Values('" & txtMgr_Last_Name & "', '" & _
    txtMgr_First_Name & "', " & chkMgr_Is_VP & ",'" & _
    txtVP & "','" & cboLocation & "')"
Code:
   Dim booIsMgr as Boolean
   booIsMgr = (Nz(Me.chkMgr_Is_VP,0) <> 0)
   StrSql1 = "INSERT INTO Managers([Mgr_Last_Name], [Mgr_First_Name], " & _
    "[Mgr_Is_VP], [Vice President], [Plan]) " & _
    " Values('" & txtMgr_Last_Name & "', '" & _
    txtMgr_First_Name & "', " & booIsMgr & ",'" & _
    txtVP & "','" & cboLocation & "')"


Duane
Hook'D on Access
MS Access MVP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top