Error de compilación: No se ha definido el Sub o Function
Publicado por Aaron (1 intervención) el 17/05/2021 23:50:56
Hola espero me puedan ayudar.
Estoy intentando enlazar Excel con Access pero me muestra este erro (Error de compilación: No se ha definido el Sub o Function) y me sombrea el Fields("Campo1") . Les dejo el código esperando que me puedan ayudar.
Estoy intentando enlazar Excel con Access pero me muestra este erro (Error de compilación: No se ha definido el Sub o Function) y me sombrea el Fields("Campo1") . Les dejo el código esperando que me puedan ayudar.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
Sub codigoformulario()
Dim Conn As ADODB.Connection
Dim MiConexion
Dim Rs As ADODB.Recordset
Dim MiBase As Long
MiBase = "BD ACSES CPM.accdb"
Set Conn = New ADODB.Connection
MiConexion = Application.ThisWorkbook.Path & Application.PathSeparator & MiBase
With Conn
.Provider = "Microsoft.ACE.OLEDB.12.0"
.Open MiConexion
End With
Set Rs = New ADODB.Recordset
Rs.CursorLocation = adUseServer
Rs.Open Source:="HERRERIA", ActiveConnection:=Conn, _
CursorType:=adOpenDynamic, _
LockType:=adLockOptimistic, _
Options:=adCmdTable
With Rs
.AddNew
Fields("Campo1") = Userforml.TextBox1.Value
Fields("Campo2") = Userforml.TextBox2.Value
End With
Rs Update
Rs.Close
Conn.Close
Set Rs = Nothing
Set Conn = Nothing
MsgBox "Alta exitosa", vbInformation, "EXCELeINFO"
End Sub
Valora esta pregunta


0