- 26 Ago 2020 às 22:29
#58257
Estou utilizando o código abaixo, mas a tabela do access não recebe os valores do formulário criado no excel.
Estou fazendo o teste com esse campo: .Fields("NOME") = Txtnome , o campo txtnome do formulalrio não é carregado no access.
Sub cmdAdd_Click()
Dim cnn As ADODB.Connection 'dim the ADO collection class
Dim rst As ADODB.Recordset 'dim the ADO recordset class
Dim dbPath
Dim x As Long, i As Long
On Error GoTo errHandler:
dbPath = ThisWorkbook.Path & "\" & "Projeto_Central.accdb;"
Set cnn = New ADODB.Connection
cnn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & dbPath & "Jet oledb:DATABASE PASSWORD=123456;"
Set rst = New ADODB.Recordset
rst.Open Source:="Cadastro", ActiveConnection:=cnn, _
CursorType:=adOpenDynamic, LockType:=adLockOptimistic, _
Options:=adCmdTable
With rst
.AddNew
.Fields("NOME") = Txtnome
.Update
End With
rst.Close
cnn.Close
Set rst = Nothing
Set cnn = Nothing
'commuinicate with the user
MsgBox " The data has been successfully sent to the access database"
On Error GoTo 0
Exit Sub
errHandler:
Set rst = Nothing
Set cnn = Nothing
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure cmdAdd"
End Sub
Estou fazendo o teste com esse campo: .Fields("NOME") = Txtnome , o campo txtnome do formulalrio não é carregado no access.
Sub cmdAdd_Click()
Dim cnn As ADODB.Connection 'dim the ADO collection class
Dim rst As ADODB.Recordset 'dim the ADO recordset class
Dim dbPath
Dim x As Long, i As Long
On Error GoTo errHandler:
dbPath = ThisWorkbook.Path & "\" & "Projeto_Central.accdb;"
Set cnn = New ADODB.Connection
cnn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & dbPath & "Jet oledb:DATABASE PASSWORD=123456;"
Set rst = New ADODB.Recordset
rst.Open Source:="Cadastro", ActiveConnection:=cnn, _
CursorType:=adOpenDynamic, LockType:=adLockOptimistic, _
Options:=adCmdTable
With rst
.AddNew
.Fields("NOME") = Txtnome
.Update
End With
rst.Close
cnn.Close
Set rst = Nothing
Set cnn = Nothing
'commuinicate with the user
MsgBox " The data has been successfully sent to the access database"
On Error GoTo 0
Exit Sub
errHandler:
Set rst = Nothing
Set cnn = Nothing
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure cmdAdd"
End Sub