I have a calendar Form that opens when I Dblck a TextBox in a Form (Reporte). The calendar form calls a Public Function (ModifcaTC) in order to calculate a Foreign Exchange rate (TC).

When I put breakpoints (F9) and step through (F8), I get the correct result but when I try to run it without breakpoints, I get different results. I have tried to put Doevents and other tricks as an act of desperation and nothing!!

The exchange rate needs to be reflected in Forms!Reportes![TC2]. Yes, Form reportes is open

Here part of the code in Calendar form:

Private Sub Form_Close()
Dim strActiveObjectName As String

.
.
.

If Application.CurrentObjectName = "Reportes" Then
Forms!Reportes![TC2] = ModificaTC(Forms!Reportes![Fecha Final])
DoEvents
End If
End sub

The Public Function (which is in the main module) looks like this:


Public Function ModificaTC(Fecha As String)
'Esta funcion es llamada para cambiar el campo TC2 en form Reportes
'Incluye el TC mas proximo a la fecha escogida

Dim db As Database
Dim rstO As Recordset


Dim strSQL, strCriteria, FechaBusq As String
Set db = CurrentDb()


strSQL = "SELECT * FROM [Tipo de Cambio];"
Set rstO = db.OpenRecordset(strSQL, dbOpenDynaset)
With rstO
If .RecordCount = 0 Then
Exit Function
End If
.MoveFirst
FechaBusq = Format(Fecha, "dd-mmm-yy")
strCriteria = "[Fecha] <= #" & FechaBusq & "#"
rstO.FindLast (strCriteria)
ModificaTC = ![TC]

End With
rstO.Close
End Function

Any ideas?