473,397 Members | 1,974 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Open form condition

5 Nibble
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
Oct 16 '20 #1

✓ answered by cactusdata

> 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
  3.  
  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
  10.  
  11. If Warning <> "" Then
  12.     MsgBox Warning, vbInformation + vbOkOnly, "Proposals"
  13. End If

3 3442
jimatqsi
1,271 Expert 1GB
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.

Jim
Oct 16 '20 #2
cactusdata
214 Expert 128KB
> 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
  3.  
  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
  10.  
  11. If Warning <> "" Then
  12.     MsgBox Warning, vbInformation + vbOkOnly, "Proposals"
  13. End If
Oct 19 '20 #3
nsagar2020
5 Nibble
Thanks for your response jimatqsi,
I will use these advises.
thanks
kind regards
Oct 21 '20 #4

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

Similar topics

7
by: TDIOwa | last post by:
I have a form that has a specific date on it. I want to open another form that has the Active Control Calendar on it. I want to open this form to the specific date on the first form. I have...
5
by: twick10 | last post by:
Hi, I am trying to execute a control method on an open form (not with focus) from a modal dialog box. I want to increment the node selected from the dialog when a certain key is pressed. Any...
2
by: allyn44 | last post by:
Hello, I have built a serch form for users to edit records. I only want them to pull up the record they need, and I want to check for nulls. There should not be dupes becasue the underlying...
2
by: erick-flores | last post by:
Hello all Form A (pk) & Form B (fk) I want to display my Form B empty whenever is the first time, that the pk form Form A, is enter. I click a button to open Form B. BUT if the pk from Form A...
3
by: kev | last post by:
Hi folks, I have a form for registration (frmRegistration) whereby i have two buttons. One is Save which saves record using the OnClick property. I used wizard to create the save button. The...
14
by: keri | last post by:
Hi, Simple version of the question..... How do I use the where clause of the open form command to show an account with a matching ID to be displayed when the form is opened? Eg. I select a...
3
by: vidhyapriya | last post by:
Hi all I am developing windows application using vb.net.I want to pass values to open form.I am opening only one form when user click the buttons several times.Useing delegate i am passing...
5
by: billa856 | last post by:
Hi, My project is in MS Access 2002. In that I want to open one form multiple times. I put one button on my main form. Now whenever I click on that button than form will be open. Now when I...
3
by: Jozo | last post by:
Dear All, I have main form "Job" and one subform "Offer" In a subform I have combo box Contacts. How can I open form Contacts if I dbl click on a combo box in my subform where condition ID =...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.