Can't seem to set property correctly (1 Viewer)

slharman1

Member
Local time
Today, 04:32
Joined
Mar 8, 2021
Messages
476
I have a time keeping form that should set properties based on the conditions of the last record such as if there are no time stamps then the time-in field should be enabled and the time-out field should not, but it is not working.
Only the second set of conditions works correctly.

Here is the code:
Code:
Private Sub Form_Load()

        DoCmd.GoToControl "SfrmTimePunch"
        DoCmd.GoToRecord , , acLast
                
        If Me!SfrmTimePunch!TimeIn = 0 And Forms!frmTimeClockEmployee!SfrmTimePunch!TimeOut = 0 Then
            Me!SfrmTimePunch.Form.DataEntry = True
            Me!SfrmTimePunch.Form!TimeIn.Enabled = True
            Me!SfrmTimePunch.Form!TimeOut.Enabled = False
            Me!SfrmTimePunch.Form!txtWONumber.Enabled = True
            Me!SfrmTimePunch.Form!txtWONumber.SetFocus
            
           ' Exit Sub
        ElseIf Me!SfrmTimePunch!TimeIn > 0 And Forms!frmTimeClockEmployee!SfrmTimePunch!TimeOut > 0 Then
            Me!SfrmTimePunch.Form.DataEntry = True
            Me!SfrmTimePunch.Form!TimeIn.Enabled = True
            Me!SfrmTimePunch.Form!TimeOut.Enabled = False
            Me!SfrmTimePunch.Form!txtWONumber.Enabled = True
            Me!SfrmTimePunch.Form!txtWONumber.SetFocus
            
            'Exit Sub
        ElseIf Forms!frmTimeClockEmployee!SfrmTimePunch!TimeIn > 0 And Forms!frmTimeClockEmployee!SfrmTimePunch!TimeOut = 0 Then
            Me!SfrmTimePunch.Form.DataEntry = False
            Me!SfrmTimePunch.Form!TimeIn.Enabled = False
            Me!SfrmTimePunch.Form!TimeOut.Enabled = True
            Me!SfrmTimePunch.Form!txtWONumber.Enabled = False
            Me!SfrmTimePunch.Form.TimeOut.SetFocus
            
        
        End If
End Sub
 

theDBguy

I’m here to help
Staff member
Local time
Today, 02:32
Joined
Oct 29, 2018
Messages
21,471
Hi. Have you tried stepping through the code already?
 

slharman1

Member
Local time
Today, 04:32
Joined
Mar 8, 2021
Messages
476
Not sure if I remember how. I will try that shortly.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 02:32
Joined
Oct 29, 2018
Messages
21,471
Not sure if I remember how. I will try that shortly.
You put a break point where you want the code to pause and then hit the F8 key to step into the code. Make sure to examine each variable as you go along. You can also use the Immediate Window to verify things.
 

Minty

AWF VIP
Local time
Today, 10:32
Joined
Jul 26, 2013
Messages
10,371
If your in's and out's are times (datetime fields display only the time) they will be null not 0 ?
 

CJ_London

Super Moderator
Staff member
Local time
Today, 10:32
Joined
Feb 19, 2013
Messages
16,610
some comments

your first set of settings are the same as the second, so why not combine them?
and are your form values 0 or actually null?
And are you sure you are on the last record?
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 05:32
Joined
Feb 19, 2002
Messages
43,266
The code does NOT belong in the Load event. The load event runs only once. If you want the code to run for each record, use the form's Current event. Also, the code should be in the subform, NOT in the main form.
 

slharman1

Member
Local time
Today, 04:32
Joined
Mar 8, 2021
Messages
476
The code does NOT belong in the Load event. The load event runs only once. If you want the code to run for each record, use the form's Current event. Also, the code should be in the subform, NOT in the main form.
Pat, thanks for chiming in you have never led me astray (along with many others)
But would the load event be ok if it a one time use, then more code closes the form.
It is only to capture a moment in time then closes.
Also the code is used to set the properties of the subform before the user can do anything, does it still go in the subform. I had a good reason (in my mind) why I put it in the main form, just can't come up with it right now :unsure:
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 05:32
Joined
Feb 19, 2002
Messages
43,266
Why? When you look at the code later and need something similar, are you going to remember that the Load event won't work? Code that works with data does not belong in the Load event. Just because it works in some instances doesn't mean you should use it "just this time". If you learn what each event is for, you will have more success in controlling the behavior of forms. You can use a screwdriver to hammer in a nail (although your fingers are in jeopardy because it will be much harder to control and the screwdriver is too light for this task so it will be difficult) but you can't use a hammer to turn a screw.

If the data you are checking is in the subform, then the code belongs in the subform.
 

slharman1

Member
Local time
Today, 04:32
Joined
Mar 8, 2021
Messages
476
Why? When you look at the code later and need something similar, are you going to remember that the Load event won't work? Code that works with data does not belong in the Load event. Just because it works in some instances doesn't mean you should use it "just this time". If you learn what each event is for, you will have more success in controlling the behavior of forms. You can use a screwdriver to hammer in a nail (although your fingers are in jeopardy because it will be much harder to control and the screwdriver is too light for this task so it will be difficult) but you can't use a hammer to turn a screw.

If the data you are checking is in the subform, then the code belongs in the subform.
Well said Pat, believe I will move the code. Thanks again. Btw, code has changed to the isnull function Instead of 0
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 05:32
Joined
Feb 19, 2002
Messages
43,266
Btw, code has changed to the isnull function Instead of 0
Much better choice. Although when you are working with a date, you might want to use IsDate()
 

slharman1

Member
Local time
Today, 04:32
Joined
Mar 8, 2021
Messages
476
Much better choice. Although when you are working with a date, you might want to use IsDate()
Thank you, I will check it out.
It would be fascinating to spend a few hours with you and try to soak up all you know about access. Amazing!
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 05:32
Joined
Feb 19, 2002
Messages
43,266
Interesting. I think we'd be hard pressed to get through all I know in a few hours.
However, if you think a session like that is worth a fair fee for my time, I would go along with it. I would suggest if you are really interested, you start a thread with a survey (PM me with a link so I don't miss it) and if enough people sign up ( 10-20 ), we can have each person submit a question or a request for some specific advice. I have GTM and I can host a meeting for 25. You can join on your phone, tablet, or computer since I'll be the presenter. You can see me and hear me from any device that supports a web browser. If we want to have the participants do screen sharing, they will need to join from a PC. I'll decide which questions I can answer in two hours (we don't want to go longer than that and believe it or not, I don't actually know everything so there may be some topics I can't actually talk about like Macros) and then people can commit and pay the agreed fee to my paypal account. We can have some backup questions in case I can get through the explanations quickly enough to get to them. I can also offer topics I think you need to learn a little about such as how joins work and how to build a combo or listbox without the wizard which is really important if you need to change an existing one. Remember, the time I spend will be much more than the two hours we are all together.

We'd have to figure out a good time depending on where people live. It would be hard to do West Coast of the US to the UK. We might need two sessions by geographical location. I'm on the East coast of the US so I'm GMT -5
 

slharman1

Member
Local time
Today, 04:32
Joined
Mar 8, 2021
Messages
476
Interesting. I think we'd be hard pressed to get through all I know in a few hours.
However, if you think a session like that is worth a fair fee for my time, I would go along with it. I would suggest if you are really interested, you start a thread with a survey (PM me with a link so I don't miss it) and if enough people sign up ( 10-20 ), we can have each person submit a question or a request for some specific advice. I have GTM and I can host a meeting for 25. You can join on your phone, tablet, or computer since I'll be the presenter. You can see me and hear me from any device that supports a web browser. If we want to have the participants do screen sharing, they will need to join from a PC. I'll decide which questions I can answer in two hours (we don't want to go longer than that and believe it or not, I don't actually know everything so there may be some topics I can't actually talk about like Macros) and then people can commit and pay the agreed fee to my paypal account. We can have some backup questions in case I can get through the explanations quickly enough to get to them. I can also offer topics I think you need to learn a little about such as how joins work and how to build a combo or listbox without the wizard which is really important if you need to change an existing one. Remember, the time I spend will be much more than the two hours we are all together.

We'd have to figure out a good time depending on where people live. It would be hard to do West Coast of the US to the UK. We might need two sessions by geographical location. I'm on the East coast of the US so I'm GMT -5
That would be awesome but in reality I don’t know anyone else programming in access. I would be willing to bet your fee is a little high for one person to absorb. That is definitely not a complaint. I bet you are worth every penny. Thank you for all your help with a newbie like me. I would be lost without people like you willing to guide some struggling to get something usable that makes life easier. Keep up the good work and should I run across any professionals wanting some DB design I will most definitely send them to you.
thank you again.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 05:32
Joined
Feb 19, 2002
Messages
43,266
I think you misunderstood where the other people would come from. But I agree, I doubt that there would be sufficient interest to set it up.
 

slharman1

Member
Local time
Today, 04:32
Joined
Mar 8, 2021
Messages
476
I think you misunderstood where the other people would come from. But I agree, I doubt that there would be sufficient interest to set it up.
I do run across businesses that might need you special talents. I will definitely send them your way when I run across them.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 05:32
Joined
Feb 19, 2002
Messages
43,266
Thanks. I'm mostly retired but I do take the occasional interesting project.
 

Users who are viewing this thread

Top Bottom