473,396 Members | 2,030 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,396 software developers and data experts.

Using conditional statement to enable and disable cmd buttons

Jerry Maiapu
259 100+
I know this is pretty much simple but my brain is jammed and I cannot really make any progress with this.
Can someone assist me with this problem?

Ok it’s to do with validation for Overtime during working days and weekend only:
I have 3 text boxes
1. TimeIn
2. TimeOut
3. DateWorked

And 3 command buttons that are disable by default:
1. cmdNew ‘On click goes to new record
2. cmdclockin ‘inserts time into TimeOut -clock out
3. cmdclockout ‘inserts date into DateWorked and time into TimeIn –clockin

On the On_Current event of the form I wish to control how these buttons are enable and disable triggered by each particular event.

Ok when a user clicks on cmdclockin to clock in, Date() and Time is inserted into DateWorked and TimeIn respectively.

I am confronted with so many if conditions and am stacked on how to logically arrange them so that they work perfectly as I wish.

This is what I would like to do:

1.If DateWorked<>date or IsNull(DateWorked)=True then
cmdNew.Enable=True

2. If IsNull(TimeIn)=True and IsNull(TimeOut )=False then
cmdclockout.Enable=True
cmdclockin.Enable=False

3. If IsNull(DateWorked)=True Then
cmdclockout.Enable= True
cmdclockin.Enable= False

4 If IsNull(DateWorked)=False And IsNull(TimeOut)=True Then
cmdclockout.Enable= False
cmdclockin.Enable= True
5. if Time<#4:06pm # then ‘they need to clock in after 4:06 pm
cmdNew.Enable=False 'Ready to Go to new record if clicked
else
cmdNew.Enable=True

I know most people will figure out the logic. The problem is that I just need to logically put these so that it works.

Thanks so much. It’s quite easy but my mind is not really fresh at this point of time because of a kind of pressure am going through and I cannot think logically at this time. So please help me out.

If anyone think that I am missing some important component do include in the solution or ask.

Thank you and thank you

Jerry
Jul 8 '10 #1
5 7585
TheServant
1,168 Expert 1GB
Statement 1 and 5 can be combined to:
Expand|Select|Wrap|Line Numbers
  1. If DateWorked <> Date Or Time < #4:06:00 PM# Then
  2.     cmdNew.Enable = True
  3. Else
  4.     cmdNew.Enable = False
  5. End If
With your statement:
Expand|Select|Wrap|Line Numbers
  1. DateWorked<>date or IsNull(DateWorked)=True
You will notice the second condition iss redundant because if DateWorked is Null it will not equal date.

The rest are simply made into two conditions:
Expand|Select|Wrap|Line Numbers
  1. If (IsNull(TimeIn) And Not IsNull(TimeOut)) Or IsNull(DateWorked) Then
  2.     cmdclockin.Enable = True
  3.     cmdclockout.Enable = False
  4. ElseIf Not IsNull(DateWorked) And IsNull(TimeOut) Then
  5.     cmdclockin.Enable = True
  6.     cmdclockout.Enable = False
  7. End If
I removed the "= True" and "= False" as they are not necessary.

Just some thoughts on making it shorter.
Jul 8 '10 #2
nico5038
3,080 Expert 2GB
I guess you don't need a [New] button, as it's clear when opening the form that there's a record for today or not.
When there isn't a record you can insert a new record with empty In and Out time fields.

Remains a test for the TimeIn to be empty or filled.
I would disable the TimeOut when the TimeIn is empty, thus only one [Set time] button will be needed.

Idea ?

Nic;o)
Jul 8 '10 #3
Jerry Maiapu
259 100+
Nico, I definitely need a New button. I know what you're saying is true usually but this a different case. Well, when opening the form if there is a record for today then we have to be sure that the user has clocked out if not then we have to disabled the new button because if not disabled people might unnecessarily insert new records without clocking out.

And for the TimeIn and TimeOut buttons what you say is what I wish to do too. But as I mentioned earlier am just perplexed here. Hope you could contribute like how TheServant replied.

TheServant, Thank you so much for relieving me. Just like what Nic;o suggested When clocked in cmdclockin and cmdNew button should be disabled while cmdclockin is enable. And after cmdNew is clicked cmdNew and cmdclockin are disable so that they only clock in at time.

I'll see and collect these ideas and put them together. But do post hints and helps

Thanks
Thanks so much
Jul 9 '10 #4
nico5038
3,080 Expert 2GB
Hmm, looks like you're trying to use an Access form as a ClockIn/Out machine.

Makes me wonder how you distinguish between the different employees. Looks to me they need to enter their (user)name first. This would allow you to check or there's for the running day a record and insert one when not present and enable the In/Out buttons depending on the value(s) found.

Another consideration is the fact or overtime is recorded in an additional record, thus making it possible to have the StartTime entered twice in one day....

Nic;o)
Jul 9 '10 #5
Jerry Maiapu
259 100+
@nico5038
Yes. Employees enter username to log in. Hereafter the clock-in/out form is loaded where the username=username.
The clock-in/out form has a subform to do the clock ins and outs. The sub form is in SINGLE FORM VIEW NOT DATA SHEET and Navigation button property is set to "NO" likewise the parent form. When someone is allowed overtime by the manager (with admin privileges) a cmdovertime button is enabled in the clock-in/out form.
The employees click on this cmdovertime button where the overtime form is loaded and that is where my problem was; in enabling/disabling cmd buttons on the overtime form.

The overtime form is just the same as clock-in/out with similar sub form & proprieties.

This is what I did.
I sliced my problem and shared it with the cmdovertime button's on click event:

Expand|Select|Wrap|Line Numbers
  1. If DateWorked <>VbSaturday or DateWorked<>VbSunday And Time < #4:06:00 PM# Then
  2. msgbox"Overtime is done after close of business hours"
  3. exit sub
  4. else
  5. docmd.OpenForm "cmdovertime"
  6.  
then I did this for the on current event for the overtime's sub form to enable/disable buttons which is ok now..thanks every one for contributions..

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Current()
  2. If DateWorked <> Date Then
  3. cmdNew.Enabled = True
  4. cmdout.Enabled = False
  5. cmdIn.Enabled = False
  6. ElseIf IsNull(TimeOut) Then
  7. cmdout.Enabled = True
  8. cmdIn.Enabled = False
  9. cmdNew.Enabled = False
  10. Else
  11. cmdout.Enabled = False
  12. cmdIn.Enabled = False
  13. cmdNew.Enabled = True
  14. End If
  15.  
  16. If IsNull(DateWorked) Then 'when cmdNew button
  17. 'is clicked DateWorked=Null therefore
  18. cmdNew.Enabled = False
  19. cmdout.Enabled = False
  20. cmdIn.Enabled = True
  21. End If
  22.  
  23. End Sub
  24.  
Jul 12 '10 #6

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

Similar topics

2
by: web developer | last post by:
hi I need to write a stored procedure that takes input parameters,and according to these parameters the retrieved fields in a select statement are chosen. what i need to know is how to make the...
1
by: hortoristic | last post by:
We are using JavaScript to Enable/Disable certain fields on web pages based on business rules. A simple example is if when using an option type tag, and the two options are Yes and No. If YES...
9
by: Susan Bricker | last post by:
Hi. I have two questions ... (1) I want to use a Listbox to enable the user to select 1 or many items from the list. However, I'm having trouble figuring out how to find out t which items have...
2
by: Dntc | last post by:
Hi All Is there anyway to enable/disable the toolbar buttons on the fly as like in MFC which helps centralizing this process?Let's i have a toolbar button ToolbarButtonSave which can be...
1
by: inadsad | last post by:
Good Day, I have 2 forms with bindingNavigator and have a simple routine to enable/disable navigator buttons. Each nav button is assigned to a tag value. The problem is that if I want to...
6
by: Brandon McCombs | last post by:
Hello, I have a form that contains a listview on the left side and a column of buttons on the right side. Only some of the buttons do I want enabled all the time. The other buttons should be...
2
by: Naushad | last post by:
Hi all, I am using the countinous form. I want to Enable/Disable the some fields for perticular records as per the following condition when open the form. I have written this code in "On Current...
2
by: iDesmet | last post by:
Hallo, First of all, I'm new at this group and I'm currently learning VB.NET by my own (later I want to learn C#, but that's another story). In other words, I'm a Newbie. Anyway, I was...
4
by: anewbornman | last post by:
I want to create a login form for multiple users with different rights, and they can only see information in my queries and reports that pertain to them. For example: User1 logins in, on the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.