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

insert statement and checkbox(y/n)

Status
Not open for further replies.

4ukh

Programmer
Jan 10, 2008
15
SA
i've a table name CRID_INDEX and have three fields (field1, field2 and chkbx(y/n) and 2nd thing is my form in which i've a checkbox... now my question is how to insert value of other two fields and chkbx using SQL INSERT statement...

thank you
regards
 

Something like...
Code:
If Me.CheckboxName Then
   [i]do something[/i]
Else
   [i]do something else[/i]
End If


Randy
 
i write the following coed for the check box where check box is cg_p_chk but not working so far...
now i me going to play with the check box with the code tip which you posted me.

thank you

regards

Code:
If cg_p_chk.Value = vbChecked Then
    frm_payment_rece = 1
    Else
    frm_payment_rece = 0
    End If



4ukh
 

How about (in the forms current event)...
Code:
frm_payment_race = cg_p_chk

Randy
 
Code:
Dim frm_payment As Integer

'check the check box state and store its position in variable frm_payment_chk
If cg_p_chk.Value = vbChecked Then
    frm_payment_rece = 1
    Else
    frm_payment_rece = 0
    End If

DoCmd.RunSQL "INSERT INTO CRID_index ([CRID], [CRID_num], [server_ip], [server_port], [payment], [validation_period], [start_date], [exp_date])" & _
                "VALUES ('" & frm_CRID &"', '" & frm_num_chop & "', '" & frm_serv_ip & "', '" & frm_serv_port & "', '" & frm_Uprice & "', '" & frm_validation & "', '" & frm_start & "', '" & frm_exp & "');"

i don't know why this check box giving me a headache...?
when i execute my code i got a dialog box to inter the frm_payment_chk value manually...

and i didn't use your code tip which you posted me before:

Code:
If Me.CheckboxName Then
   frm_payment_chk = 1
Else
   frm_payment_chk = 0
End If


thanks for the help

best regards



4ukh
 
i used your code but gives an error:

Code:
If Me.CheckboxName Then
   frm_payment_chk = 1
Else
   frm_payment_chk = 0
End If

i fixed the problem by myself but still not very successful to obtain the check box value and push that to the table; some times it works and some time not...

Code:
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
    'get the cg_chp_num value for the number of record entries
    Do While x < cg_chp_num
        x = x + 1
'increment the Vtemp field value
        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 just noticed that when i click the chop it button to store the record into the table either the check box in the form is checked or not checked in the table this check appear once checked and second time not check...
i don't know why please help me out..

i've posted the code above


thank you

best regards
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top