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

Using conditional statement to enable and disable cmd buttons

Jerry Maiapu
100+
P: 259
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
Share this Question
Share on Google+
5 Replies


TheServant
Expert 100+
P: 1,168
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
Expert 2.5K+
P: 3,072
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
100+
P: 259
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
Expert 2.5K+
P: 3,072
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
100+
P: 259
@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

Post your reply

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