Всем доброе время суток.
 
этот код добавляет данные в Access.Sub CallAddTransfer()
 
    
 
    Dim WS As Worksheet
 
    Dim Qty As Integer
 
    Set WS = Worksheets("AddRecords")
 
    FinalRow = WS.Cells(65536, 1).End(xlUp).Row
 
    Ctr = 0
 
    For i = 7 To FinalRow
 
        Style = Cells(i, 1).Value
 
        FromStore = Cells(i, 2).Value
 
        ToStore = Cells(i, 3).Value
 
        Qty = Cells(i, 4).Value
 
        Ctr = Ctr + 1
 
        Application.StatusBar = "Adding Record " & Ctr
 
        AddTransfer Style, FromStore, ToStore, Qty
 
    Next i
 
    Application.StatusBar = False
 
    MsgBox Ctr & " records added."
 
    
 
End Sub
 
 
 
Sub AddTransfer(Style As Variant, FromStore As Variant, ToStore As Variant, Qty As Integer)
 
    ' Page 466
 
    Dim cnn As ADODB.Connection
 
    Dim rst As ADODB.Recordset
 
    
 
    MyConn = ThisWorkbook.Path & Application.PathSeparator & "transfers.mdb"
 
    
 
    ' open the connection
 
    Set cnn = New ADODB.Connection
 
    With cnn
 
        .Provider = "Microsoft.Jet.OLEDB.4.0"
 
        .Open MyConn
 
    End With
 
    
 
    ' Define the Recordset
 
    Set rst = New ADODB.Recordset
 
    rst.CursorLocation = adUseServer
 
    
 
    ' open the table
 
    rst.Open Source:="tblTransfer", _
 
    ActiveConnection:=cnn, _
 
    CursorType:=adOpenDynamic, _
 
    LockType:=adLockOptimistic, _
 
    Options:=adCmdTable
 
    
 
    ' Add a record
 
    rst.AddNew
 
    
 
    ' Set up the values for the fields. The first four fields
 
    ' are passed from the calling userform. The date field
 
    ' is filled with the current date.
 
    rst("Style") = Style
 
    rst("FromStore") = FromStore
 
    rst("ToStore") = ToStore
 
    rst("Qty") = Qty
 
    rst("tDate") = Date
 
    rst("Sent") = False
 
    rst("Receive") = False
 
    
 
    ' Write the values to this record
 
    rst.Update
 
    
 
    ' Close
 
    rst.Close
 
    cnn.Close
 
End Sub
 
 
 
 
 
рабочая книга EXCEL находится в одной папке вместе с файлом ACCESS/
 
 
Как можно переделать данный макрос в VB.NET?
 
 
 как изменить провайдер  Microsoft.Jet.OLEDB.4.0"
 
на oledb 
Ответить
        |