Vba to Access record Insert Issue

Posted by raam on Stack Overflow See other posts from Stack Overflow or by raam
Published on 2010-05-28T08:54:30Z Indexed on 2010/05/28 9:21 UTC
Read the original article Hit count: 220

Filed under:
|
|

I want to insert Values to access table by using VBA control is there is any simple way to do this. i try this code but it does not work properly if i run this code it give the error 'variable not set' can anyone help me. thanks in advance

Private Sub CommandButton1_Click()
Dim cn As ADODB.Connection
    Dim strSql As String
    Dim lngKt As Long
    Dim dbConnectStr As String
    Dim Catalog As Object
    Dim cnt As ADODB.Connection
    Dim dbPath As String

    Dim myRecordset As New ADODB.Recordset
    Dim SQL As String, SQL2 As String

    dbPath = "table.accdb"
    dbConnectStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dbPath & ";"

   SQL = "INSERT INTO Jun_pre (ProductName,DESCRIPTION,SKU,MT,(mt),MRP,Remark,no_of_units_in_a_case) VALUES (""aa"",""bb"",""test"",""testUnit"",""1"",""2"",,""3"",,""4"");"

        With cnt
        .Open dbConnectStr 'some other string was there
        .Execute (SQL)
        .Close
    End With
End Sub

© Stack Overflow or respective owner

Related posts about sql

Related posts about ms-access