Open form condition

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nsagar2020
    New Member
    • Sep 2020
    • 5

    #1

    Open form condition

    Hi All
    I've an access database, in which I'm trying to open form based on time (stored in a field [Close_Time], in a table). So, my logic is if current date-time is greater than [Close_Time], then open form else some message. I have entered following code in "On Click" event of a button
    Code:
    Dim tm As Date
    tm = Me.Close_Time.Value
    If TimeValue(Now) <= tm Then
        Warning = "You can't open proposals as of now"
    Else
        DoCmd.OpenForm "Proposals", acNormal, "", "[RFQID]=" & RFQID, , acNormal
    End If
    But when I click on button, nothing is happening!
    Can you pls. suggest if I need to do something else.
    Thanks in advance
  • jimatqsi
    Moderator Top Contributor
    • Oct 2006
    • 1293

    #2
    You might try using the datediff function to compare the two time values. Now() returns the date and time - is the same format in the tm variable?
    Code:
    datediff("N",date1,date2)
    returns the difference between 2 date fields in minutes. If the first field is < the second field you get a positive result, otherwise you get a negative result, or zero if they are equal.

    Also, do you know how to use the debugger? Just click on the code where you want to stop, hit the F9 key to get the program to stop on that line. (Use the Debug drop-down menu to guide how to step through the code). Point at a variable to get the value. That will get you started.

    Jim

    Comment

    • cactusdata
      Recognized Expert New Member
      • Aug 2007
      • 223

      #3
      > But when I click on button, nothing is happening!

      That's because the current time was earlier than the value of Close_Time.

      But you could extent it to do something no matter when the button is clicked:

      Code:
      Dim tm      As Date
      Dim Warning As String
      
      tm = Me!Close_Time.Value
      If Time < tm Then
          Warning = "You can't open proposals before " & Format(tm, "h:nn") & "."
      Else
          DoCmd.OpenForm "Proposals", acNormal, "", "[RFQID]=" & RFQID, , acNormal
      End If
      
      If Warning <> "" Then
          MsgBox Warning, vbInformation + vbOkOnly, "Proposals"
      End If

      Comment

      • nsagar2020
        New Member
        • Sep 2020
        • 5

        #4
        Thanks for your response jimatqsi,
        I will use these advises.
        thanks
        kind regards

        Comment

        Working...