hi guys...!
when i tried to insert the form's information into the database either the check box in the form is checked or not once this check box in the table appear as checked and second time unchecked...

i don't know why that is happening...?
please help out...

thank you

best regards


4ukh

Private Sub Chop_it_Click()

    Dim Vtemp As Integer
    Dim x As Integer
    Vtemp = 0
    x = 0
    
    

    
    'Here first we check whether or not if any record exists in the table
    If CurrentDb.OpenRecordset("SELECT COUNT(CRID_index.CRID_num) FROM CRID_index")(0) > 0 Then
        Vtemp = CurrentDb.OpenRecordset("SELECT MAX(CRID_index.CRID_num) FROM CRID_index WHERE CRID_index.CRID = '" & cg_txtCRID & "' ")(0)
    Else
        Vtemp = 0
    End If
    MsgBox Vtemp
    'check the check box state and assign the value
    If cg_p_chk.Value = vbChecked Then
       cg_p_chk = 1
    Else
       cg_p_chk = 0
    End If
    
    Do While x < cg_chp_num
        x = x + 1
        Vtemp = Vtemp + 1

        'fals for all worning while inseting the records
        DoCmd.SetWarnings fals
        'basic SQL statement for the table CRID_index
        DoCmd.RunSQL "INSERT INTO CRID_index ([CRID], [CRID_num], [server_ip], [server_port], [payment], [payment_rece_chk], [validation_period], [start_date], [exp_date])" & _
                "VALUES ('" & cg_txtCRID & "', '" & Vtemp & "' , '" & cg_txtservIP & "', '" & cg_serv_port & "', '" & cg_unit_price & "', '" & cg_p_chk & "', '" & cg_validation & "', '" & cg_start & "', '" & cg_exp & "');"
    Loop
    
    MsgBox "All valuable records are successfully inserted into the database."
    
End Sub

I don't see anything wrong in how you save checkbox's checked state to DB.
You do read this information back in to the form, right? You may have some error in how you read and set checkbox's state.

Hi,

In Access Value for High / True is -1

so change this to :

If cg_p_chk.Value = vbChecked Then
     cg_p_chk = -1
  Else
     cg_p_chk = 0
  End If

So, While Getting Records back, Check for 0

If RS("MyCheckField") = 0 Then
  MyCheckBox.Value = vbUnChecked
Else
  MyCheckBox.Value = vbChecked
End If

Regards
Veena

QVeen is quite right, but basically it doesn't matter what is saved to DB. The original code works, if the saved data is read:

If RS("MyCheckField") = 1 Then
  MyCheckBox.Value = vbChecked
Else
  MyCheckBox.Value = vbUnChecked
End If

I admit that interpreting RS("MyCheckField") = 0 as an "unchecked" value and any other value as a "checked" value is the safest solution :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.