Hi guy i'm writing a program using vb the main page when the user choose in the combo box active = yes then insert into table1 then active=no then insert into table2

Here is my code please check for me why got error and correct me if i'm wrong

Private Sub cmdAdd_Click()


If cboActive.Value = True Then
     cnUni.Execute "Insert into staff_badgeTrackingNew ( '" & txtID.Text & "','" & txtEmpID.Text & "','" & txtEmp_Name.Text & "'," & txtDepart.Text & "','" & cboActive.Value & "','" & cboStatus.Value & "','" & cboLoct.Value & "','" & cboCard.Value & "','" & txtApp.Text & "''" & txtCompany.Text & "')"
        ClearAll
Else
        cnUnisql.Execute "Insert into staff_badgeTracking( '" & txtID.Text & "','" & txtEmpID.Text & "','" & txtEmp_Name.Text & "'," & txtDepart.Text & "','" & cboActive.Value & "','" & cboStatus.Value & "','" & cboLoct.Value & "','" & cboCard.Value & "','" & txtApp.Text & "''" & txtCompany.Text & "')"
        ClearAll

End If

Clear
End Sub

Once again insert into (field) value (thevaluetobeinserted)


Good Luck

Can you write out the example instead of explain it. thank you

Sir/ma'am, I will not do your work for you. You can hire me but I will not do your work for you for free.

Insert Into sometable (field) values (valuetobeinserted)


Please use the help system of access or sql. Use web searches or whatever, but most of all use your mind sir/ma'am.


Good Luck

Sir/ma'am, I will not do your work for you. You can hire me but I will not do your work for you for free.

Insert Into sometable (field) values (valuetobeinserted)


Please use the help system of access or sql. Use web searches or whatever, but most of all use your mind sir/ma'am.


Good Luck

Thank anyways

Hi guy i'm writing a program using vb the main page when the user choose in the combo box active = yes then insert into table1 then active=no then insert into table2

Here is my code please check for me why got error and correct me if i'm wrong

Private Sub cmdAdd_Click()


If cboActive.Value = True Then
     cnUni.Execute "Insert into staff_badgeTrackingNew ( '" & txtID.Text & "','" & txtEmpID.Text & "','" & txtEmp_Name.Text & "'," & txtDepart.Text & "','" & cboActive.Value & "','" & cboStatus.Value & "','" & cboLoct.Value & "','" & cboCard.Value & "','" & txtApp.Text & "''" & txtCompany.Text & "')"
        ClearAll
Else
        cnUnisql.Execute "Insert into staff_badgeTracking( '" & txtID.Text & "','" & txtEmpID.Text & "','" & txtEmp_Name.Text & "'," & txtDepart.Text & "','" & cboActive.Value & "','" & cboStatus.Value & "','" & cboLoct.Value & "','" & cboCard.Value & "','" & txtApp.Text & "''" & txtCompany.Text & "')"
        ClearAll

End If

Clear
End Sub

Hi Gingank

What are the options of your combo box. If it is "yes" and "No" then
use the text value of the combo box.

If cboActive.Text = "Yes" Then
cnUni.Execute "Insert into staff_badgeTrackingNew ( '" & txtID.Text & "','" & txtEmpID.Text & "','" & txtEmp_Name.Text & "'," & txtDepart.Text & "','" & cboActive.Value & "','" & cboStatus.Value & "','" & cboLoct.Value & "','" & cboCard.Value & "','" & txtApp.Text & "''" & txtCompany.Text & "');"
ClearAll
Else
cnUnisql.Execute "Insert into staff_badgeTracking( '" & txtID.Text & "','" & txtEmpID.Text & "','" & txtEmp_Name.Text & "'," & txtDepart.Text & "','" & cboActive.Value & "','" & cboStatus.Value & "','" & cboLoct.Value & "','" & cboCard.Value & "','" & txtApp.Text & "''" & txtCompany.Text & "');"
ClearAll

End If

Note: You have also not specified which backend database you are using. Some database make it mandatory to have a semi colon (;) to be appened as the last character of the SQL query. I have also used it in the code given above. Do tell me if you are still having problem

You are both forgetting to define which fields data is being inserted to...

Hence....

INSERT INTO TableName (FieldName) VALUES (ValueToBeInserted)

This article has been dead for over six months. Start a new discussion instead.