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é.
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é.