Reading SQL data into checkbox

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mke1981
    New Member
    • Mar 2008
    • 2

    #1

    Reading SQL data into checkbox

    Please someone help, i have been playing with the line of code for two days and still not getting anywhere.

    I have a checkbox on my form called Chkrugby when this is clicked and saved to the sql table it is saved as 1, the data type on my sql table for this is set to bit. writing the data is fine and this works well the code is below.




    Set rsRemote = New ADODB.Recordset

    rsRemote.Open "cadets", sqlRemote, adOpenDynamic, adLockOptimisti c

    Me.Caption = "Setting values"
    DoEvents
    rsRemote.AddNew
    rsRemote.Fields ("chkrugby") = Me.chkrugby.Val ue
    rsRemote.Update
    rsRemote.Close
    Set myRS = Nothing


    the problem is when i am trying to load the same form that has been saved i am unable to populate the chkrugby box.

    i have tryed the blow but hitting a wall please can anyone help?

    Me.chkrugby = rsRemote.Fields ("chkrugby")

    i have also tryed

    If rsRemote.Fields ("chkrugby") = 1 Then Form1.chkrugby = 1

    also

    If rsRemote.Fields ("chkrugby") = 1 Then Me.chkrugby = vbChecked
    If rsRemote.Fields ("chkrugby") = 0 Then Me.chkrugby.Val ue = vbUnchecked

    and

    If rsRemote.value( "chkrugby") = 1 Then Form1.chkrugby = 1
    Last edited by mke1981; Mar 22 '08, 07:10 PM. Reason: Wrote combo box, instead of checkbox
  • mafaisal
    New Member
    • Sep 2007
    • 142

    #2
    Hello
    Try This
    Code:
    If rsRemote.Fields("chkrugby") = 'True' Then Me.chkrugby.value = 1
     If rsRemote.Fields("chkrugby") = 'False' Then Me.chkrugby.value = 0
    I think this will work bcoz u use chkrugby as bit

    Faisal

    Originally posted by mke1981
    Please someone help, i have been playing with the line of code for two days and still not getting anywhere.

    I have a checkbox on my form called Chkrugby when this is clicked and saved to the sql table it is saved as 1, the data type on my sql table for this is set to bit. writing the data is fine and this works well the code is below.




    Set rsRemote = New ADODB.Recordset

    rsRemote.Open "cadets", sqlRemote, adOpenDynamic, adLockOptimisti c

    Me.Caption = "Setting values"
    DoEvents
    rsRemote.AddNew
    rsRemote.Fields ("chkrugby") = Me.chkrugby.Val ue
    rsRemote.Update
    rsRemote.Close
    Set myRS = Nothing


    the problem is when i am trying to load the same form that has been saved i am unable to populate the chkrugby box.

    i have tryed the blow but hitting a wall please can anyone help?

    Me.chkrugby = rsRemote.Fields ("chkrugby")

    i have also tryed

    If rsRemote.Fields ("chkrugby") = 1 Then Form1.chkrugby = 1

    also

    If rsRemote.Fields ("chkrugby") = 1 Then Me.chkrugby = vbChecked
    If rsRemote.Fields ("chkrugby") = 0 Then Me.chkrugby.Val ue = vbUnchecked

    and

    If rsRemote.value( "chkrugby") = 1 Then Form1.chkrugby = 1

    Comment

    Working...