Update Data

G

gatarossi

Dear all,

In this code below, excel exports to access all information in the
sheet, the accounting code, profit center, period and value. But I
need to change this code, because if I already had in the table of
access this combination: accounting code, profit center and period I
need only change the value and not include the same combination and
the new value. How can I do it?

Sub exporta_teste()

Dim cnn As ADODB.Connection
Dim rst As ADODB.Recordset
FinalRow = Cells(65536, 1).End(xlUp).Row - 1

MyConn = "C:\Documents and Settings\brspagi\Meus documentos\teste
\controle_despesas.mdb"

Set cnn = New ADODB.Connection
With cnn
.Provider = "Microsoft.Jet.OLEDB.4.0"
.Open MyConn
End With

Set rst = New ADODB.Recordset
rst.CursorLocation = adUseServer

rst.Open Source:="orcamento_despesas", _
ActiveConnection:=cnn, _
CursorType:=adOpenDynamic, _
LockType:=adLockOptimistic, _
Options:=adCmdTable

Dim contador As Long
contador = 7

For Each Cell In Range("a1:a" & FinalRow)
If Cell.Value <> "" Then
ActiveCell.Select

rst.AddNew

rst("codigo_conta_contabil") = ActiveSheet.Range("A" & contador)
rst("codigo_centro_custo") = ActiveSheet.Range("B3")
rst("periodo") = ActiveSheet.Range("C6")
rst("valor_transacao") = ActiveSheet.Range("C" & contador)

rst.Update

contador = contador + 1
End If
Next Cell

rst.Close
cnn.Close

Exit Sub

Erro: MsgBox Err.Description

End Sub

Thanks a lot!

André.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Import multiple Access Queries 0
Database in Excel 0
Access to Excel format 2
Exclude Data 2
Exclude Data 0
Exclude Data of Access 3
Adding table into existing access database via ADO 0
SQL - Sum Values 0

Top