elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.
 
Inicio Ayuda Buscar Ingresar Registrarse
26 Mayo 2012, 15:22  


Tema destacado: [AIO elhacker.NET] Compilación herramientas análisis y desinfección malware

+  Foro de elhacker.net
|-+  Programación
| |-+  Desarrollo Web
| | |-+  Boton Importar en access
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Boton Importar en access  (Leído 452 veces)
ship

Desconectado Desconectado

Mensajes: 10


Ver Perfil
Boton Importar en access
« en: 11 Enero 2012, 07:38 »

Hola.
Quisiera saber como importo datos de excel a una tabla en access. Lo que hice fue lo siguiente en un formulario en blanco inserte un botón, en el evento al hacer clic coloque el código.
Lo que me pidieron es un boton dentro de  un formulario con el nombre importar, no busque la ruta de la hoja de excel al seleccionarla nos inserte los datos en la tabla de acces.
Pero me marca un error que dice " ERROR DECOMPILACION" NO SE HA DEFINIDO EL TIPO DEFINIDO POR EL USUARIO.


mI codigo el es siguiente:
Private Sub Comando47_Click()
Const DBFile = "proyectoo.mdb"
Const ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
Const XLfile = "pruebas.xlsx"

Dim connection As New ADODB.connection --------> ERROR
Dim rs As New ADODB.Recordset
Dim rs1 As New ADODB.Recordset
Dim Dato As Variant
Dim Dato1 As Variant
Dim MiFSO  As FileSystemObject
Dim MiArchivo As File
Dim sCarpeta As String, sCarpetaDest As String
Dim Columna_Actual As Integer
Dim lista As String, grupo As String

Dim s As String 'semestre
Dim g As String 'grupo

Dim c As Integer


s = semestre.Value
g = grupo.Value



lista = s & "_" & g & "_" & i


sCarpeta = CurrentProject.Path & "\" & XLfile
sCarpetaDest = CurrentProject.Path & "\" & lista & ".xlsx"
'connection.Open ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\access\Final.mdb")
connection.Open (ConnectionString & CurrentProject.Path & "\" & DBFile)
Set MiFSO = New FileSystemObject
Set MiArchivo = MiFSO.GetFile(sCarpeta)
MiArchivo.Copy sCarpetaDest, True
Set MiArchivo = Nothing
Set MiFSO = Nothing

' Abre el libro de Excel
Set Obj_Excel = CreateObject("Excel.Application")
MsgBox "Archivos excel: " & sCarpetaDest
Obj_Excel.Workbooks.Open FileName:=sCarpetaDest
' si es la versión de Excel 97, asigna la hoja activa ( ActiveSheet )
 If Val(Obj_Excel.Application.Version) >= 8 Then
     Set Obj_Hoja = Obj_Excel.ActiveSheet
 Else
        Set Obj_Hoja = Obj_Excel
 End If

' Open connection


 'Abre la tabla a la que se le van a insertar datos
'   rs1.Open " select * from grupo where semestre.semestres=" & s & " and semestre.periodo=" & p & " and semestre.inicio=" & i, connection, adOpenDynamic, adLockReadOnly
   
     
     ' rs.Open "select * from alumno where grupo =" & grupo & " order by apellido_paterno", connection, adOpenDynamic, adLockReadOnly
    rs.Open "SELECT GRUPO.clave, ALUMNO.nombre, ALUMNO.matricula, ALUMNO.apellido_paterno, ALUMNO.apellido_materno FROM (SEMESTRE INNER JOIN GRUPO ON SEMESTRE.clave = GRUPO.semestre) INNER JOIN ALUMNO ON GRUPO.clave = ALUMNO.grupo WHERE (((SEMESTRE.inicio)='" & i & "') AND ((GRUPO.grupo)='" & g & "') AND ((SEMESTRE.periodo)='" & p & "')" & " AND ((SEMESTRE.semestres)= '" & s & "'))", connection, adOpenDynamic, adLockReadOnly
    ' No results?
   ' rst_Ado.Open "Select NomProducto FROM Productos", connection, adOpenStatic, adLockPessimistic
    Obj_Hoja.Cells(8, 3) = g
    Obj_Hoja.Cells(8, 5) = "M"
    Obj_Hoja.Cells(6, 30) = s
   
   
c = 0
    Columna_Actual = 13
    Do Until rs.EOF
        ' Getting current template from recordset.
        Dato = rs("apellido_paterno") & " " & rs("apellido_materno") & " " & rs("nombre")
        Dato1 = rs("matricula")
        ' If it's not a valid template, skip it
        If Not (IsNull(Dato)) Then
        Obj_Hoja.Cells(Columna_Actual, 3) = Dato
        Obj_Hoja.Cells(Columna_Actual, 2) = Dato1
        Columna_Actual = Columna_Actual + 1
        c = c + 1
         
End If
 rs.MoveNext
Loop

Obj_Hoja.Cells(45, 34) = c
   
    MsgBox "Datos copiados"
   Obj_Excel.ActiveWorkbook.Save
   
    If connection.State = adStateOpen Then connection.Close
    Obj_Excel.ActiveWorkbook.Close
    Obj_Excel.Quit
    Set Obj_Hoja = Nothing
    Set Obj_Excel = Nothing
    Set FileDlg = Nothing



End Sub


En línea
Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
importar a access
Software
lulial77 0 238 Último mensaje 4 Agosto 2006, 17:13
por lulial77
Importar .dll
.NET
DarkItachi 5 1,274 Último mensaje 9 Julio 2008, 23:49
por MANULOMM
importar dll de c++ en c#
.NET
^kazike^ 6 3,183 Último mensaje 10 Septiembre 2009, 13:37
por ^kazike^
usa el boton de minimizar como un boton
Programación Visual Basic
andrer03 1 812 Último mensaje 10 Julio 2010, 01:59
por xkiz ™
mover un boton con otr boton ¬
Programación Visual Basic
LunaHAck 2 372 Último mensaje 24 Julio 2011, 08:24
por LunaHAck
Powered by SMF 1.1.16 | SMF © 2006-2008, Simple Machines