ADO - Add

Private Sub cmdADD_Click()
   
    On Error GoTo ERR_MAIN

    Dim objRS As ADODB.Recordset
    Dim intI As Integer
    Dim strFields
    Dim strValues
   
    Set objConn = New ADODB.Connection
    Set objRS = New ADODB.Recordset
   
    ''1 CONNECT TO THE DATA SOURCE
    If Me.chkOracle Then
        objConn.ConnectionString = "Provider=OraOLEDB.Oracle;Data Source=yti;" & _
                             "User ID=scott;Password=tiger;"
    Else
        objConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
                     "Data Source=C:\JPI\11th Batch Training\dbMSAccess.mdb"
    End If
                
    objConn.Open

    ''2 OPEN RECORDSET
    With objRS
       
        .Open "EMP", objConn, adOpenKeyset, adLockOptimistic
       
        For intI = 1 To 2
            strFields = Array("EMPNO", "ENAME", "JOB", "MGR", "HIREDATE", "SAL", "COMM", "DEPTNO")
            strValues = Array(9997 + intI, "EDMON" & CStr(intI), "ANALYST", 7566, #4/1/2002#, 1000 * intI, 500 * intI, 40)
           
            ''Tell Access that we want to be in "add" mode
            .AddNew strFields, strValues
                        
            ''To accept new record
            .Update
        Next
       
        ''Close the recordset
        .Close
   
    End With
   
    objConn.Close
    Exit Sub
   
ERR_MAIN:
    MsgBox Err.Number & " : " & Err.Description
End Sub

comment 0 comments:

Post a Comment

Delete this element to display blogger navbar

 
© C.L.S.T.I. Tutorial | Design by Blog template in collaboration with Concert Tickets, and Menopause symptoms
Powered by Blogger