macros command for excel dialog

J

jeff

i make excel dialog i put ( textbox for Name, text box for Time In, text box for Time out, command button for Ok and Command Button for Cancel) the inside of excel workbook i have plenty of work sheet with the name of our deferent staf. What i want is if i fill up all the information in excel dialog it will transfer the data to worksheet....

thanks a lot for the help...
 
D

Dave Peterson

You may want to look into Data|Form.

If you try this and find it less than optimal, you could use John Walkenbach's
enhanced data form:

http://j-walk.com/ss/dataform/index.htm

I put 3 textboxes on a user form:
Textbox1 held the name, textbox2&3 held the times

I put 2 buttons on the form:
commandbutton1 was cancel
commandbutton2 was "write to sheet"

And I wrote to the next open row based on column A in sheet2.

Here's my code:

Option Explicit
Dim blkProc As Boolean
Private Sub CommandButton1_Click()
Unload Me
End Sub
Private Sub CommandButton2_Click()

Dim oRow As Long

With Worksheets("sheet2")
oRow = .Cells(.Rows.Count, "A").End(xlUp).Row + 1
.Cells(oRow, "A").Value = Me.TextBox1.Value
.Cells(oRow, "B").Value = TimeValue(Trim(Me.TextBox2.Value))
.Cells(oRow, "C").Value = TimeValue(Trim(Me.TextBox3.Value))
End With

blkProc = True
Me.TextBox1.Value = ""
Me.TextBox2.Value = ""
Me.TextBox3.Value = ""
blkProc = False
Me.CommandButton2.Enabled = False

End Sub
Private Sub TextBox1_Change()
If blkProc Then Exit Sub
Call CheckWriteButton
End Sub
Private Sub TextBox2_Change()
If blkProc Then Exit Sub
Call CheckWriteButton
End Sub
Private Sub TextBox3_Change()
If blkProc Then Exit Sub
Call CheckWriteButton
End Sub
Private Sub UserForm_Initialize()

With Me.CommandButton1
.Enabled = True
.Caption = "Cancel"
End With

With Me.CommandButton2
.Enabled = False
.Caption = "Write to Sheet"
End With

End Sub
Sub CheckWriteButton()

Dim iCtr As Long
Dim okToWrite As Boolean
Dim testTime As Variant

okToWrite = True
If Trim(Me.TextBox1.Value) = "" Then
okToWrite = False
Else
For iCtr = 2 To 3
testTime = ""
On Error Resume Next
testTime = TimeValue(Trim(Me.Controls("textbox" & iCtr).Value))
On Error GoTo 0

If testTime = "" Then
okToWrite = False
Exit For
Else
If Application.Text(testTime, "[h]:mm") _
= Trim(Me.Controls("textbox" & iCtr).Value) Then
'ok
Else
'not yet
okToWrite = False
End If
End If
Next iCtr
End If

Me.CommandButton2.Enabled = okToWrite
End Sub

I also assumed that you'd type h:mm or hh:mm (no seconds).
 
J

jeff

To: Dave

Thanks a lot Dave your very helpfull..

Thanks once again,

jeff

Dave Peterson said:
You may want to look into Data|Form.

If you try this and find it less than optimal, you could use John Walkenbach's
enhanced data form:

http://j-walk.com/ss/dataform/index.htm

I put 3 textboxes on a user form:
Textbox1 held the name, textbox2&3 held the times

I put 2 buttons on the form:
commandbutton1 was cancel
commandbutton2 was "write to sheet"

And I wrote to the next open row based on column A in sheet2.

Here's my code:

Option Explicit
Dim blkProc As Boolean
Private Sub CommandButton1_Click()
Unload Me
End Sub
Private Sub CommandButton2_Click()

Dim oRow As Long

With Worksheets("sheet2")
oRow = .Cells(.Rows.Count, "A").End(xlUp).Row + 1
.Cells(oRow, "A").Value = Me.TextBox1.Value
.Cells(oRow, "B").Value = TimeValue(Trim(Me.TextBox2.Value))
.Cells(oRow, "C").Value = TimeValue(Trim(Me.TextBox3.Value))
End With

blkProc = True
Me.TextBox1.Value = ""
Me.TextBox2.Value = ""
Me.TextBox3.Value = ""
blkProc = False
Me.CommandButton2.Enabled = False

End Sub
Private Sub TextBox1_Change()
If blkProc Then Exit Sub
Call CheckWriteButton
End Sub
Private Sub TextBox2_Change()
If blkProc Then Exit Sub
Call CheckWriteButton
End Sub
Private Sub TextBox3_Change()
If blkProc Then Exit Sub
Call CheckWriteButton
End Sub
Private Sub UserForm_Initialize()

With Me.CommandButton1
.Enabled = True
.Caption = "Cancel"
End With

With Me.CommandButton2
.Enabled = False
.Caption = "Write to Sheet"
End With

End Sub
Sub CheckWriteButton()

Dim iCtr As Long
Dim okToWrite As Boolean
Dim testTime As Variant

okToWrite = True
If Trim(Me.TextBox1.Value) = "" Then
okToWrite = False
Else
For iCtr = 2 To 3
testTime = ""
On Error Resume Next
testTime = TimeValue(Trim(Me.Controls("textbox" & iCtr).Value))
On Error GoTo 0

If testTime = "" Then
okToWrite = False
Exit For
Else
If Application.Text(testTime, "[h]:mm") _
= Trim(Me.Controls("textbox" & iCtr).Value) Then
'ok
Else
'not yet
okToWrite = False
End If
End If
Next iCtr
End If

Me.CommandButton2.Enabled = okToWrite
End Sub

I also assumed that you'd type h:mm or hh:mm (no seconds).


i make excel dialog i put ( textbox for Name, text box for Time In, text box for Time out, command button for Ok and Command Button for Cancel) the inside of excel workbook i have plenty of work sheet with the name of our deferent staf. What i want is if i fill up all the information in excel dialog it will transfer the data to worksheet....

thanks a lot for the help...
 
J

jeff

Can you
give me again another code that will automatically show the precent time
in textbox.

Or when they key in there name under textbox1 the time will show in
textbox2 as there time in then recorded the data to the worksheet. Next
time they key in there name will the time out the time will show to
texbox3.

Thanks,

jeff
jeff said:
To: Dave

Thanks a lot Dave your very helpfull..

Thanks once again,

jeff

Dave Peterson said:
You may want to look into Data|Form.

If you try this and find it less than optimal, you could use John Walkenbach's
enhanced data form:

http://j-walk.com/ss/dataform/index.htm

I put 3 textboxes on a user form:
Textbox1 held the name, textbox2&3 held the times

I put 2 buttons on the form:
commandbutton1 was cancel
commandbutton2 was "write to sheet"

And I wrote to the next open row based on column A in sheet2.

Here's my code:

Option Explicit
Dim blkProc As Boolean
Private Sub CommandButton1_Click()
Unload Me
End Sub
Private Sub CommandButton2_Click()

Dim oRow As Long

With Worksheets("sheet2")
oRow = .Cells(.Rows.Count, "A").End(xlUp).Row + 1
.Cells(oRow, "A").Value = Me.TextBox1.Value
.Cells(oRow, "B").Value = TimeValue(Trim(Me.TextBox2.Value))
.Cells(oRow, "C").Value = TimeValue(Trim(Me.TextBox3.Value))
End With

blkProc = True
Me.TextBox1.Value = ""
Me.TextBox2.Value = ""
Me.TextBox3.Value = ""
blkProc = False
Me.CommandButton2.Enabled = False

End Sub
Private Sub TextBox1_Change()
If blkProc Then Exit Sub
Call CheckWriteButton
End Sub
Private Sub TextBox2_Change()
If blkProc Then Exit Sub
Call CheckWriteButton
End Sub
Private Sub TextBox3_Change()
If blkProc Then Exit Sub
Call CheckWriteButton
End Sub
Private Sub UserForm_Initialize()

With Me.CommandButton1
.Enabled = True
.Caption = "Cancel"
End With

With Me.CommandButton2
.Enabled = False
.Caption = "Write to Sheet"
End With

End Sub
Sub CheckWriteButton()

Dim iCtr As Long
Dim okToWrite As Boolean
Dim testTime As Variant

okToWrite = True
If Trim(Me.TextBox1.Value) = "" Then
okToWrite = False
Else
For iCtr = 2 To 3
testTime = ""
On Error Resume Next
testTime = TimeValue(Trim(Me.Controls("textbox" & iCtr).Value))
On Error GoTo 0

If testTime = "" Then
okToWrite = False
Exit For
Else
If Application.Text(testTime, "[h]:mm") _
= Trim(Me.Controls("textbox" & iCtr).Value) Then
'ok
Else
'not yet
okToWrite = False
End If
End If
Next iCtr
End If

Me.CommandButton2.Enabled = okToWrite
End Sub

I also assumed that you'd type h:mm or hh:mm (no seconds).


i make excel dialog i put ( textbox for Name, text box for Time In, text box for Time out, command button for Ok and Command Button for Cancel) the inside of excel workbook i have plenty of work sheet with the name of our deferent staf. What i want is if i fill up all the information in excel dialog it will transfer the data to worksheet....

thanks a lot for the help...
 
D

Dave Peterson

You can populate and format a textbox with something like:
me.textbox2.value = format(now,"hh:mm")

But if you're reading the pc's date/time, maybe you could just show them what
you're doing and not have them type at all.

I put textbox1, label1, commandbutton1 and commandbutton2 in a userform:

Option Explicit

Dim LogWks As Worksheet
Dim ActionIsCheckIn As Boolean
Dim CurTime As Date
Dim DestCell As Range
Private Sub CommandButton1_Click()
Unload Me
End Sub
Private Sub CommandButton2_Click()

With DestCell
If ActionIsCheckIn Then
.Offset(0, 2).Value = CurTime
MsgBox "Check In time logged"
Else
.Value = Me.TextBox1.Value
.Offset(0, 1).Value = CurTime
MsgBox "Check Out time logged"
End If
End With

Call CommandButton1_Click

End Sub
Private Sub TextBox1_Change()

Dim iRow As Long
Dim LastRow As Long
Dim FirstRow As Long
Dim myMsg As String

Call CheckWriteButton
If Me.CommandButton2.Enabled = False Then
myMsg = "Please type your name"
Else
With LogWks
FirstRow = 2 'headers in row 1???
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row

'assume they're checking out
ActionIsCheckIn = False
Set DestCell = .Cells(LastRow + 1, "A")
myMsg = "Check Out Time" & " -- " & Format(CurTime, "hh:mm:ss")
For iRow = LastRow To FirstRow Step -1
If StrComp(.Cells(iRow, "A").Value, _
Me.TextBox1.Value, vbTextCompare) = 0 Then
ActionIsCheckIn = IsEmpty(.Cells(iRow, "C"))
If ActionIsCheckIn Then
Set DestCell = .Cells(iRow, "A")
myMsg = "Check In Time" & " -- " _
& Format(CurTime, "hh:mm:ss")
End If
Exit For
End If
Next iRow
End With
End If

Me.Label1.Caption = myMsg

End Sub
Private Sub UserForm_Initialize()

Set LogWks = Worksheets("sheet2")

With Me.CommandButton1
.Enabled = True
.Caption = "Cancel"
End With

With Me.CommandButton2
.Enabled = False
.Caption = "Ok"
End With

CurTime = Now
Me.Label1.Caption = "Please type your name"

End Sub
Sub CheckWriteButton()

Dim okToWrite As Boolean

okToWrite = True
If Trim(Me.TextBox1.Value) = "" Then
okToWrite = False
End If

Me.CommandButton2.Enabled = okToWrite

End Sub

===========
This seemed to work ok. It just started at the bottom of the log worksheet and
looked for a matching name. When it found the first one, it looked to see if
column C (check In) was filled. If it was, then that meant that the user should
be checking out--if it was empty, they should be checking back in.

But I'm not sure I'd use something like this.

If I (as an employee) forgot to check in, then I'd be off by one cycle. And if
I were a trouble maker, I'd type someone else's name--or just mistype mine own.
You could spend lots of time making sure things are ok.

Maybe you could add a combobox (instead of a textbox) that only allows the user
to pick from a list. Then add a top secret password for each person to validate
their entry.

In fact, if you look at the textbox properties, you'll see a passwordchar that
can be used to hide the typed value.

Maybe validating name against password would be sufficient. But then you'd
still have trouble with people forgetting to log in/log out.

======
I think I'd check eBay for time clocks!

Good luck,



Can you
give me again another code that will automatically show the precent time
in textbox.

Or when they key in there name under textbox1 the time will show in
textbox2 as there time in then recorded the data to the worksheet. Next
time they key in there name will the time out the time will show to
texbox3.

Thanks,

jeff
jeff said:
To: Dave

Thanks a lot Dave your very helpfull..

Thanks once again,

jeff

Dave Peterson said:
You may want to look into Data|Form.

If you try this and find it less than optimal, you could use John Walkenbach's
enhanced data form:

http://j-walk.com/ss/dataform/index.htm

I put 3 textboxes on a user form:
Textbox1 held the name, textbox2&3 held the times

I put 2 buttons on the form:
commandbutton1 was cancel
commandbutton2 was "write to sheet"

And I wrote to the next open row based on column A in sheet2.

Here's my code:

Option Explicit
Dim blkProc As Boolean
Private Sub CommandButton1_Click()
Unload Me
End Sub
Private Sub CommandButton2_Click()

Dim oRow As Long

With Worksheets("sheet2")
oRow = .Cells(.Rows.Count, "A").End(xlUp).Row + 1
.Cells(oRow, "A").Value = Me.TextBox1.Value
.Cells(oRow, "B").Value = TimeValue(Trim(Me.TextBox2.Value))
.Cells(oRow, "C").Value = TimeValue(Trim(Me.TextBox3.Value))
End With

blkProc = True
Me.TextBox1.Value = ""
Me.TextBox2.Value = ""
Me.TextBox3.Value = ""
blkProc = False
Me.CommandButton2.Enabled = False

End Sub
Private Sub TextBox1_Change()
If blkProc Then Exit Sub
Call CheckWriteButton
End Sub
Private Sub TextBox2_Change()
If blkProc Then Exit Sub
Call CheckWriteButton
End Sub
Private Sub TextBox3_Change()
If blkProc Then Exit Sub
Call CheckWriteButton
End Sub
Private Sub UserForm_Initialize()

With Me.CommandButton1
.Enabled = True
.Caption = "Cancel"
End With

With Me.CommandButton2
.Enabled = False
.Caption = "Write to Sheet"
End With

End Sub
Sub CheckWriteButton()

Dim iCtr As Long
Dim okToWrite As Boolean
Dim testTime As Variant

okToWrite = True
If Trim(Me.TextBox1.Value) = "" Then
okToWrite = False
Else
For iCtr = 2 To 3
testTime = ""
On Error Resume Next
testTime = TimeValue(Trim(Me.Controls("textbox" & iCtr).Value))
On Error GoTo 0

If testTime = "" Then
okToWrite = False
Exit For
Else
If Application.Text(testTime, "[h]:mm") _
= Trim(Me.Controls("textbox" & iCtr).Value) Then
'ok
Else
'not yet
okToWrite = False
End If
End If
Next iCtr
End If

Me.CommandButton2.Enabled = okToWrite
End Sub

I also assumed that you'd type h:mm or hh:mm (no seconds).



jeff wrote:

i make excel dialog i put ( textbox for Name, text box for Time In, text box for Time out, command button for Ok and Command Button for Cancel) the inside of excel workbook i have plenty of work sheet with the name of our deferent staf. What i want is if i fill up all the information in excel dialog it will transfer the data to worksheet....

thanks a lot for the help...
 
J

jeff

Hi Dave,

i have put already the your code in one userform.. labe1, textbox1,
commandbutton1, commandbutton2 and addition i put another textbox (textbox3)
for the name of the staff and this textbox3 if they put there name it will go
to other sheet (example: the sheet name is jeff) so if they key in the name
jeff it will send the data to sheet for jeff. Because the my excel sheet is
like this>>>> Column A 10:40 is for the Fix date for the whole one month,
Culomn B & C, row 10:40 is Worked Time the B 10:40 is for Wroked In and C
10:40 is for End Time, Column D & E is for the Lunch Break D 10:40 for Lunch
Out, e 10:40 is for Lunch In, The Column F & G is for Break Time, F 10:40 is
for Break Out, F 10:40 is for Break In.

The Second code that you have given to me is can work in one sheeet only
(sheet2) and just add in and add in the names in Column A and Time in Column
C & D but this ok but i wonder how can i compute all the times of the workers
after the end of the month.

Can I ask again another favor form you to make a codes for the above data
information......

Thanks

jeff
 
D

Dave Peterson

You could use a worksheet formula to just subtract the times to get
the net working time (Timeout-timein = total worked).

Then use a pivottable to make a summary by person, by month, etc.
 
J

jeff

hi Dave,

What is the command if i put the command button ( save ) inside the form the
save all the changes in whole worksheet and commandbutton ( exit ) to exit
the worksheet...

thanks
 
D

Dave Peterson

If you want to save the workbook, you can use:

activeworkbook.save
but since the code is in the workbook to save, I'd use:
thisworkbook.save

then to close the workbook (not worksheet),

activeworkbook.close savechanges:=false 'since you just saved
or probably
thisworkbook.close savechanges:=false
 
Top