By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
462,885 Members | 805 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 462,885 IT Pros & Developers. It's quick & easy.

Open form condition

P: 3
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
Expand|Select|Wrap|Line Numbers
  1. Dim tm As Date
  2. tm = Me.Close_Time.Value
  3. If TimeValue(Now) <= tm Then
  4.     Warning = "You can't open proposals as of now"
  5. Else
  6.     DoCmd.OpenForm "Proposals", acNormal, "", "[RFQID]=" & RFQID, , acNormal
  7. 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
4 Days Ago #1
Share this Question
Share on Google+
2 Replies

Expert 100+
P: 1,244
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?
Expand|Select|Wrap|Line Numbers
  1. 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.

3 Days Ago #2

Expert 100+
P: 122
> 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:

Expand|Select|Wrap|Line Numbers
  1. Dim tm      As Date
  2. Dim Warning As String
  4. tm = Me!Close_Time.Value
  5. If Time < tm Then
  6.     Warning = "You can't open proposals before " & Format(tm, "h:nn") & "."
  7. Else
  8.     DoCmd.OpenForm "Proposals", acNormal, "", "[RFQID]=" & RFQID, , acNormal
  9. End If
  11. If Warning <> "" Then
  12.     MsgBox Warning, vbInformation + vbOkOnly, "Proposals"
  13. End If
1 Days ago #3

Post your reply

Sign in to post your reply or Sign up for a free account.