Private Sub Form_Open(Cancel As Integer)
Dim rst As DAO.Recordset
Dim strSQL As String
Dim strMonth As String
Dim strYear As String
Dim dtLastMonth As Date
Dim dtStart As Date
' Obtener el primer día del mes anterior
dtLastMonth = DateAdd("m", -1, Date)
dtStart = DateSerial(Year(dtLastMonth), Month(dtLastMonth), 1)
' Obtener el último día del mes anterior
dtLastMonth = DateAdd("d", -1, dtStart)
' Obtener el mes y año del mes anterior
strMonth = Format(dtLastMonth, "mmmm")
strYear = Format(dtLastMonth, "yyyy")
' Construir la consulta para obtener los últimos registros del mes anterior
strSQL = "SELECT * FROM YourTable WHERE Month(YourDateField) = " & Month(dtLastMonth) & " AND Year(YourDateField) = " & Year(dtLastMonth)
' Abrir el recordset con los últimos registros del mes anterior
Set rst = CurrentDb.OpenRecordset(strSQL)
' Recorrer los registros y aplicar formato condicional
Do Until rst.EOF
' Obtener el control correspondiente al registro actual
Me.Controls("YourControlName").SetFocus
' Verificar si el registro está en el mes anterior y aplicar el formato
If Me.YourDateField >= dtStart And Me.YourDateField <= dtLastMonth Then
Me.YourControlName.FontBold = True ' Aplicar formato en negrita
Else
Me.YourControlName.FontBold = False ' Aplicar formato normal
End If
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
End Sub