Ver Mensaje Individual
  #1 (permalink)  
Antiguo 09/08/2007, 12:09
Avatar de DaVisEx
DaVisEx
 
Fecha de Ingreso: junio-2007
Mensajes: 15
Antigüedad: 16 años, 9 meses
Puntos: 0
Pregunta AYUDAAA... No me BOta Error..

HAber tengo este ejemplo q lo modifique ..pero nada q raro ... haber quien me ayuda... okis.. ahi ba .. :

Sub exportaraacces()
Dim cn As ADODB.Connection, rs As ADODB.Recordset, n As Long
Dim nfila As String

If [a2] = Empty Then
MsgBox prompt:="No hay datos para exportar", Buttons:=vbOKOnly + vbCritical, Title:="Campos vacios"
Exit Sub
End If

Set cn = New ADODB.Connection
cn.Open "provider=microsoft.jet.oledb.4.0; " & "data source=" & ThisWorkbook.Path & "\Enlace.mdb;"
Set rs = New ADODB.Recordset
rs.Open "Datos", cn, adOpenKeyset, adLockOptimistic, adCmdTable
n = 2

Do While Range("a" & n) <> Empty
With rs
.AddNew
.Fields("Nombre") = Range("a" & n).Value
.Fields("Apellido") = Range("b" & n).Value
.Fields("Edad") = Range("c" & n).Value
.Fields("Carrera Profesional") = Range("d" & n).Value
.Fields("Otras Carreras") = Range("e" & n).Value
.Fields("Condicion") = Range("f" & n).Value
.Fields("Desaprobado") = Range("g" & n).Value
.Fields("Eventos") = Range("h" & n).Value
.Fields("Practicas") = Range("i" & n).Value
End With
n = n + 1
Loop

With rs
.AddNew
.Fields("Nombre") = Range("a" & n).Value
.Fields("Apellido") = Range("b" & n).Value
.Fields("Edad") = Range("c" & n).Value
.Fields("Carrera Profesional") = Range("d" & n).Value
.Fields("Otras Carreras") = Range("e" & n).Value
.Fields("Condicion") = Range("f" & n).Value
.Fields("Desaprobado") = Range("g" & n).Value
.Fields("Eventos") = Range("h" & n).Value
.Fields("Practicas") = Range("i" & n).Value
End With

Set rs = Nothing
cn.Close
Set cn = Nothing

MsgBox prompt:="Los datos fueron enviados correctamente", Buttons:=vbOKOnly, Title:="DATOS EXPORTADOS"

If [a3] = Empty Then
Range("a2", Selection.End(xlToRight)).ClearContents
Exit Sub
End If

nfila = Range("A65535").End(xlUp).Row
Range("a2:d" + nfila).ClearContents
End Sub
Sub formulario1()
Formulario.Show
End Sub


este codigo es parte del modulo....el q esta arriba..

ahora del mi formulario.. :

Private Sub CommandButton1_Click()
Dim Nombre As String, Apellidos As String, CarreraProfesional As String, OtrasCarreras As String, Condicion As String, Desaprobado As String, Eventos As String, Practicas As String, celda As String

Nombre = Len(TextBox1)
Apellidos = Len(TextBox2)
CarreraProfesional = Len(TextBox4)
OtrasCarreras = Len(TextBox5)
Condicion = Len(TextBox6)
Desaprobado = Len(TextBox7)
Eventos = Len(TextBox8)
Practicas = Len(TextBox9)



If [a2] = Empty Then
[a2].Select
GoTo ingresar:
End If
[a1].End(xlDown).Offset(1, 0).Select

ingresar:
celda = ActiveCell.Row
Range("a" + celda) = TextBox1
Range("b" + celda) = TextBox2
Range("c" + celda) = Val(Round(TextBox3, 0))
Range("d" + celda) = TextBox4
Range("e" + celda) = TextBox5
Range("f" + celda) = TextBox6
Range("g" + celda) = TextBox7
Range("h" + celda) = TextBox8
Range("i" + celda) = TextBox9

TextBox1 = Empty
TextBox2 = Empty
TextBox3 = Empty
TextBox4 = Empty
TextBox5 = Empty
TextBox6 = Empty
TextBox7 = Empty
TextBox8 = Empty
TextBox9 = Empty

TextBox1.SetFocus
TextBox2.SetFocus
TextBox3.SetFocus
TextBox4.SetFocus
TextBox5.SetFocus
TextBox6.SetFocus
TextBox7.SetFocus
TextBox8.SetFocus
TextBox9.SetFocus
TextBox1.SetFocus
End Sub

Private Sub CommandButton2_Click()
Call exportaraacces
End Sub


si se dan cuenta este tiene dos botones el cual es para ingresarlo a excel y el otro es para exportar a access..

pero cuando lo mando ... y escribo todo normal... cuando lo exporto a acces me bota un error en la parte de ..:

Do While Range("a" & n) <> Empty
With rs
.AddNew
.Fields("Nombre") = Range("a" & n).Value <----- aqui me sale error.... me dice q no se encontro elemento en la coleccion q corresponde con el nombre o cardinal pedido.
.Fields("Apellido") = Range("b" & n).Value
.Fields("Edad") = Range("c" & n).Value
.Fields("Carrera Profesional") = Range("d" & n).Value
.Fields("Otras Carreras") = Range("e" & n).Value
.Fields("Condicion") = Range("f" & n).Value
.Fields("Desaprobado") = Range("g" & n).Value
.Fields("Eventos") = Range("h" & n).Value
.Fields("Practicas") = Range("i" & n).Value
End With
n = n + 1
Loop



bueno con esto les pido ayudaaa... porq no se q pasa .. ? .. bueno gracias..