Saltar al contenido
View in the app

A better way to browse. Learn more.

Ayuda Excel

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Ayuda para hacer consulta de fechas de Excel a Access

publicado

Buenas

Estoy intentando crear un macro para generar un reporte entre periodos que están en las celdas " D5 " y  " F5 " de una tabla de Access, pero no logro que funcione. acudo a ustedes para que me ayuden a definir cual sera el error.

Formato de la fecha en Access "29/07/2020 10:48:51" 

Application.ScreenUpdating = True

NumId = (Format(Worksheets("usuarioF1").Range("D5").Value, "DD-MMM-YYYY") & "# ")
NumIh = (Format(Worksheets("usuarioF1").Range("F5").Value, "DD-MMM-YYYY") & "# ")
Set Cnn = New ADODB.Connection
With Cnn

    .Provider = "Microsoft.ACE.OLEDB.12.0"
    .ConnectionString = "\01.Datos\Registro.accdb"
    .Open

End With

Set Rs = New ADODB.Recordset

Sql = "SELECT nombre, cedula, riesgo, Nombre_Patrono, fecha1 FROM f_adeudos WHERE fecha => '" & NumId & "' and fecha => '" & NumIh & "' ORDER BY fecha1"

Rs.Open Sql, Cnn

Sheets("reporte").Select
Range("B7:E100").ClearContents
Range("B7").CopyFromRecordset Rs
Rs.Close

 

Muchas gracias por toda la ayuda.

Featured Replies

publicado

Hola

Para registros entre fechas debes usar "Between", algo así:

Sql = "SELECT nombre, cedula, riesgo, Nombre_Patrono, fecha1 FROM f_adeudos WHERE fecha  Between '" & NumId & "' and fecha '" & NumIh & "' ORDER BY fecha1"

Ojo, digo "algo así" ya que no tengo tus datos para probar y en realidad lo de las fechas tiene algunos detalles relacionados a la configuración regional y a los formato y tipos de datos. Prueba y comentas.

publicado
  • Autor

hola 

tiene razón mejor adjunto el archivo para que lo puedan observar

https://mega.nz/file/4FBQgCpa#VrXomOq-yDOXvQjLAU6HozVO21MwEPUOsNQ1lyHg7cI

Saludos gracias por la ayuda

macro.zip

Editado el por marcosab

publicado

Hola, dada la configuración de tus datos, lo ideal es que uses lo siguiente:

Sub f_Actualizar_7()

Dim Cnn As New ADODB.Connection
Dim Rs As New ADODB.Recordset
Dim Sql As String, Datos As Variant
Dim NumId As Date, numih As Date

NumId = Format(Range("D3").Value, "mm/dd/yyyy")
numih = Format(Range("F3").Value, "mm/dd/yyyy hh:mm:ss")

 
Set Cnn = New ADODB.Connection
With Cnn
    .Provider = "Microsoft.ACE.OLEDB.12.0"
    .ConnectionString = "Data Source=" & ThisWorkbook.Path & "\Registro.accdb"
    .Open
End With

Set Rs = New ADODB.Recordset

Sql = "SELECT nombre, cedula, riesgo, Nombre_Patrono, fecha1 FROM f_adeudos WHERE fecha1 Between #" & NumId & "# and #" & numih & "# ORDER BY fecha1"

Rs.Open Sql, Cnn

Sheets("usuarioF7").Select
Range("B7:E100").ClearContents
Range("B7").CopyFromRecordset Rs

Rs.Close
Cnn.Close

Set Rs = Nothing
Set cn = Nothing

End Sub

Ojo que necesariamente debes tener algo así en F3: 29/05/2020  23:59:00

Saludos.

Archivado

Este tema está ahora archivado y está cerrado a más respuestas.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.