attempting to code a punch clock

zrx1200

Well-known Member
Joined
Apr 14, 2010
Messages
622
Office Version
  1. 2019
Platform
  1. Windows
Layout in columns is:

Name, Date, In, Out

1)find name, if not input name, date and in time. (first button push) Punched in
2)check that punch out is empty, if yes, punch out. (second button push).
3)if user presses button again (3) code sees this and says already punched in.

Current code I can get one "run" completed correctly, but any after this no.

See code line red. This is because the name now will not = cell ever.

I need different logic but what? Any thoughts?

Code:
[Private Sub CbDana_Click()
Dim name As String
 name = "Dana"
 Dim frmcontrol As MSForms.Control
' frmcontrol = "CbDana"
 
 
 Call PlaceTime(name, CbDana)
End Sub

Code:
Public Sub PlaceTime(name As String, frmcontrol As MSForms.Control)
Dim worksht As String
Dim addme As Range
Dim LastRow As Long
'Dim selectedName As String
Dim cell As Range
Dim Myierror As Integer
Dim rng As Range
Myierror = 0
 worksht = Worksheets("Newidea").Range("S16")

    With ActiveSheet
    LastRow = Cells(.Rows.count, "AH").End(xlUp).row + 1
    End With
 Myierror = 0
 
 Call NameSearch(name, Myierror)
 
 
 
 
 If Myierror = 1 Then Exit Sub
 
 
Set addme = Sheets(worksht).Cells(LastRow, 34)
           addme = addme.Offset(0, 0)
           addme.value = name
Set addme = addme.Offset(0, 1)
            addme.value = Date
Set addme = addme.Offset(0, 1)
            addme.value = Time()
              
If Time() > TimeValue("12:50:00PM") Then
      frmcontrol.BackColor = vbRed
      frmcontrol.Caption = "LATE"
      Application.Wait (Now + TimeValue("00:00:03"))
      frmcontrol.Caption = name
    frmcontrol.BackColor = vbWhite
 Else
     frmcontrol.BackColor = vbGreen
      frmcontrol.Caption = "Ok"
      Application.Wait (Now + TimeValue("00:00:03"))
     frmcontrol.Caption = name
     frmcontrol.BackColor = vbWhite
End If
'hideAllSheets
End Sub

Code:
Private Sub NameSearch(name As String, Myierror As Integer)
'Call findrowname(name, Myierror)
Dim rng As Range
Dim cell As Range
Dim LastRow As Long
'FindNamev2 (name)
' Call findrowname(name, Myierror)
 
'
With ActiveSheet
    LastRow = Cells(.Rows.count, "AH").End(xlUp).row + 1
End With
Set rng = ActiveSheet.Range("AH3:AH8")
  For Each cell In rng
  'Below line allows first preson in to punch in
 If cell = "" Then Exit Sub
'      If IsEmpty(cell) Then Exit Sub
     If cell = name _
       And IsEmpty(cell.Offset(0, 3)) = False Then
         MsgBox "Sorry, you already punched in"
         Myierror = 1
   Exit Sub
'      End
 Else
   cell.Offset(0, 3) = Time()
   Myierror = 1
   Exit Sub
' End
' MsgBox "no"
End If
'   If cell <> name Then Exit Sub
  Next cell
'
End Sub
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Re: attempting to code a pucnh clock

Not sure where your entering the name you want to be signed in.
I would suggest using a ActiveX Combobox loaded with names. The user would either select a name from Combobox or type in a name to the Combobox.

Then we would have two Activex Command Buttons.
One for sign in and one for sign out.

If the user had already signed in you would get a warning message
If the user had already signed out you would get a warning message

Would this work for you?

And it appears as if the names would be column (34) Date in column(35) and time in column(35) and time out Column(36)

Is this correct?

What happens on the second day when he signs in?
Does the Date and times from previous day get over written?

The Reason for the ComboBox is so user may select form list or enter new name.


If this will not work please explain your coding provided more clearly.
 
Upvote 0
Re: attempting to code a pucnh clock

Not sure where your entering the name you want to be signed in.
I would suggest using a ActiveX Combobox loaded with names. The user would either select a name from Combobox or type in a name to the Combobox.

Then we would have two Activex Command Buttons.
One for sign in and one for sign out.

Yes, all names have there own command buttons laid out as first procedure in post. This supplies proper name.



And it appears as if the names would be column (34) Date in column(35) and time in column(35) and time out Column(36)

Is this correct?

Yes, correct. As the month fills up with each days "recording" I need to find each name for that day and see if they have punched in or not punched out and test accordingly and take steps to do so.


What happens on the second day when he signs in?
Does the Date and times from previous day get over written?

The second name will post. When you go to punch out second name it adds it in again as if your punching in, not punching out. Why? Because in procedure search name line (unable to get back in to message edit to red color?) cell=name the first name it see is first name, not second name (which is who is punching in at this time).

Call code works flawless for first one punched in and out and with a check you had done so, but the search name procedure needs to be able to pick the names out for that day hence need both name and date and punch out checked to put in correct info
 
Upvote 0
Re: attempting to code a pucnh clock

Your saying if you have 100 employees you have 100 buttons with their names on the buttons.
Is this what your saying?
If so your creating a lot of buttons with a lot of code to put into each button.
There is a better way then this to do things.
Why not just let them select there name from a Combobox

You said:
Yes, all names have there own command buttons laid out as first procedure in post. This supplies proper name.
 
Upvote 0
Re: attempting to code a pucnh clock

Yes like drop down will look into it. Only 7 people involved. Opps combo box I should say.
 
Last edited:
Upvote 0
Re: attempting to code a pucnh clock

While the combo box idea is another avenue to research we still have not solved or gotten any closer to solving the original issue.

Code:
And it appears as if the names would be column (34) Date in column(35) and time in column(35) and time out Column(36)

Yes its laid out like above.
 
Upvote 0
Re: attempting to code a pucnh clock

You are correct I have not addressed fixing or writing a script to do things the way I believe your trying to do things.

If you have 7 workers
And each worker has a sign in button and a button to check name and a button for sign out and maybe even one more.

That makes for 25 or so buttons.

Then we need a script for each button and on and on

I'm not able to help you with doing things this way. And normally we do not tell a script to click another button. We would just tell the script to run the other script.

But I'm sure there are others here on this forum who will be able to help you.

And I'm still not sure what happens the second day when the user signs in. I asked that question but did not understand your answer

If the sign in name goes in column "A" on day one where does the sign in name go on day two?

Does it just get added into the lastrow in column "A"

So Column A would look like this:

John
Susan
Bill
Emily
John
Susan
Emily
Bill
Bob
Susan


And so on:



So if John signed in 30 times during the Month of January you would see John's name 30 times in column "A"

And I'm sure then your going to want and total up John's total hours worked during that Month Or day or Year
 
Upvote 0
Re: attempting to code a pucnh clock

You are correct I have not addressed fixing or writing a script to do things the way I believe your trying to do things.

If you have 7 workers
And each worker has a sign in button and a button to check name and a button for sign out and maybe even one more.

That makes for 25 or so buttons.

Then we need a script for each button and on and on

I'm not able to help you with doing things this way. And normally we do not tell a script to click another button. We would just tell the script to run the other script.

But I'm sure there are others here on this forum who will be able to help you.

And I'm still not sure what happens the second day when the user signs in. I asked that question but did not understand your answer

If the sign in name goes in column "A" on day one where does the sign in name go on day two?

Does it just get added into the lastrow in column "A"

So Column A would look like this:

John
Susan
Bill
Emily
John
Susan
Emily
Bill
Bob
Susan


And so on:



So if John signed in 30 times during the Month of January you would see John's name 30 times in column "A"

And I'm sure then your going to want and total up John's total hours worked during that Month Or day or Year

Hello Sir,

Not to be rude, but I think your making this way to complicated with buttons and all.

Each person has one button. When they click there button your punched in. When you click again your punched out and if you clicked again your already done. This is determined by test what condition are being met (cells empty or not) and also the problem area which I'm trying to convey.
This is all laid out in the code and works great for one time then the problems starts as the code (in current) form pics up the first name found and is a none match and kicks out.
It would be very simple to copy code, create a form with button and my code. This way you'll see.

And yes the whole month will be in the columns we are discussing.

So, each day will see 7 entries and if 31 days 7*31 = 217 entries which is irrelevant at this time.
 
Upvote 0
Re: attempting to code a pucnh clock

Thanks to anyone who help. Now have code running.
 
Upvote 0

Forum statistics

Threads
1,214,427
Messages
6,119,419
Members
448,895
Latest member
omarahmed1

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top