I have a table that keeps track of exchange rates from dollar to NIS (local currency). Every time someone starts the program it is supposed to check if today’s rate is in. If it is in then it puts the rate on the startup switchboard. If not then it asks for the rate and puts the number in a table (tblYatzig), and then posts the rate on the switchboard. All of this runs from the on open event of the switchboard which opens when the program opens.
The way it checks if a rate was entered for today is by a DMAX for date in the table tblyatzig, and then comparing that to today’s date. If they are equal then it uses today’s date to find the existing rate in the table.
IT DOES NOT WORK when it hits the DLOOKUP. The code is below any help would be greatly appreciated.
Thanks
Private Sub Form_Open(Cancel As Integer)
Dim curYatzig As Currency
Dim x As Variant
Dim dtNow As Date
Dim DtMax As Date
Dim rst As Recordset
Set rst = New Recordset
Set rst.ActiveConnection = CurrentProject.Connection
rst.CursorType = adOpenKeyset
rst.LockType = adLockOptimistic
rst.Open (“tblyatzig”)
dtNow = Now()
DtMax = DMax(“[dtYatzig]”, “tblyatzig”)
dtNow = Format(dtNow, “short date”)
Debug.Print DtMax & ” now ” & dtNow
If dtNow > DtMax Then
curYatzig = InputBox(“Enter rate”, “thanks”)
DoCmd.OpenForm “frmmain”, acNormal, , , , acHidden
Forms![frmMain].[CurSharYtzig] = curYatzig
With rst
.AddNew
!intyatzig = curYatzig
!dtyatzig = dtNow
.Update
End With
rst.Close
Set rst = Nothing
Else
rst.Close
Set rst = Nothing
Debug.Print DtMax
curYatzig = DLookup(“[intYatzig]”, “tblYatzig”, “[dtYatzig]=#” & DtMax & “#”)
‘
Debug.Print curYatzig
DoCmd.OpenForm “frmmain”, acNormal, , , , acHidden
Forms![frmMain].[CurSharYtzig] = curYatzig
End If
End Sub