IMPORTAR EXCEL A ACCESS MEDIANTE BOTON
Publicado por oemor (7 intervenciones) el 28/12/2016 23:35:27
buenas tardes amigos espero su ayuda explico:
necesito crear un boton o command en access 2010 y que al darle click me importe un archivo excel el cual lo tengo en C:/ el cual tiene las siguientes columnas (NOMBRE, APPELLIDO, DIRECCION, TELEFONO),
he creado una tabla en access con los mismos registros (NOMBRE, APPELLIDO, DIRECCION, TELEFONO), y la nombre como DATOS.
1.-necesito que al darle clik al boton me jale los datos del excel y lo pegue a la tabla DATOS
este es el codigo que tengo pero unicamente me jala los datos del excel, no me agrega los datos a la tabla DATOS. ALGO ESTOY HACIENDO MAL EN EL INSERT INTO, ACA NECESITO SU APOYO.
*****************************CODIGO*****************************************
*********************************************************
2.- LO OTRO QUE NECESITO ES QUE UNA VEZ QUE AGREGUE LOS DATOS A LA TABLA "DATOS", TENER OTRO BOTON QUE AL DARLE CLICK ME GENERE UN ARCHIVO EXCEL EN UNA RUTA ESPECIFICA (PUEDE SER C), DE LA TABLA DATOS.
ESTO SI NO HE ENCONTRADO COMO HACERLE EN INTERNET.
BASICAMENTE NECESITO IMPORTAR ARCHIVO CON NUEVOS DATOS UNA Y OTRA VEZ ALIMENTANDO LA TABLA DATOS Y QUE LUEGO GENERE MI EXCEL CON TODOS ESOS DATOS.
PERO NO ME LO INSERTA QUE TENDRE MAL EN MI CODIGO??
SALUDOS..
necesito crear un boton o command en access 2010 y que al darle click me importe un archivo excel el cual lo tengo en C:/ el cual tiene las siguientes columnas (NOMBRE, APPELLIDO, DIRECCION, TELEFONO),
he creado una tabla en access con los mismos registros (NOMBRE, APPELLIDO, DIRECCION, TELEFONO), y la nombre como DATOS.
1.-necesito que al darle clik al boton me jale los datos del excel y lo pegue a la tabla DATOS
este es el codigo que tengo pero unicamente me jala los datos del excel, no me agrega los datos a la tabla DATOS. ALGO ESTOY HACIENDO MAL EN EL INSERT INTO, ACA NECESITO SU APOYO.
*****************************CODIGO*****************************************
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
Option Compare Database
Private Sub Comando0_Click()
Dim XlsRuta As String
Dim miSql As String
XlsRuta = "c:\BASE.xlsx" 'ACA LE INDICO LA RUTA DONDE ESTA EL ARCHIVO.
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel7, "TExcel", XlsRuta, True ' ACA IMPORTO LOS DATOS A UNA TABLA LLAMADA TExcel CREADA DE MANERA TEMPORAL, YA QUE AL FINAL SE BORRA SOLA.
miSql = "INSERT INTO DATOS (NOMBRE, APPELLIDO, DIRECCION, TELEFONO)" 'DEFINO LO QUE QUIERO IMPORTAR A MI TABLA DATOS.
miSql = miSql & " SELECT TExcel.NOMBRE, TExcel.APPELLIDO,TExcel.DIRECCION,TExcel.TELEFONO FROM TExcel" 'ACA JALO LOS DATOS DE LA TABLA.
'Ejecutamos la consulta
DoCmd.SetWarnings False
DoCmd.RunSQL (miSql)
DoCmd.SetWarnings True
'Borramos la tabla TExcel que sirvio de manera temporal.
DoCmd.DeleteObject acTable, "TExcel"
'lanza mensaje de datos anexados.
MsgBox "Datos anexados correctamente", vbInformation, "OK"
End Sub
*********************************************************
2.- LO OTRO QUE NECESITO ES QUE UNA VEZ QUE AGREGUE LOS DATOS A LA TABLA "DATOS", TENER OTRO BOTON QUE AL DARLE CLICK ME GENERE UN ARCHIVO EXCEL EN UNA RUTA ESPECIFICA (PUEDE SER C), DE LA TABLA DATOS.
ESTO SI NO HE ENCONTRADO COMO HACERLE EN INTERNET.
BASICAMENTE NECESITO IMPORTAR ARCHIVO CON NUEVOS DATOS UNA Y OTRA VEZ ALIMENTANDO LA TABLA DATOS Y QUE LUEGO GENERE MI EXCEL CON TODOS ESOS DATOS.
PERO NO ME LO INSERTA QUE TENDRE MAL EN MI CODIGO??
SALUDOS..
Valora esta pregunta


0