Re: Adding an extra record base on value selected on current recor
by Jan T. » Sat, 24 May 2008 04:58:44 GMT
ell after some difficulties I ended up with this code (tried to translate
it to english):
Private Sub RealizeTo_AfterUpdate()
Dim EmpId As Long
Dim Reason As Long
Dim strDep As String
Dim WrkDate As Date
Dim myDate As Date
Dim dtmFrom As Date
Dim dtmUntil As Date
Dim W0Prs As Double
Dim W50Prs As Double
Dim W100Prs As Double
Dim W133Prs As Double
Dim Realz2 As Integer
Dim TmeStp As Date
Dim rs As New ADODB.Recordset
Set rs.ActiveConnection = CurrentProject.Connection
myDate = DateSerial(Year(Date), 12, 31)
' Dato settes automatisk etter valgt alternativ. Blankt hvis Avspasering.
With Me ' 'myDate ' DateSerial(Year(Date), Month(Date) + 1, 15)
If .RealizeTo.Value = 2 Or .RealizeTo.Value = 4 Or .RealizeTo.Value
= 5 _
Or .RealizeTo.Value = 6 Then
.DateToRealize = DateSerial(Year(Date), Month(Date) + 1, 15)
ElseIf .RealizeTo.Value = 1 Or .RealizeTo.Value = 3 Then
If .RealizeTo.Value = 3 Then .DateToRealize =
DateSerial(Year(Date), 12, 31)
If .RealizeTo.Value = 1 Then _
.DateToRealize = InputBox("What date do you want to take
time off: mm\dd\yyyy", _
"Date to take time off; mm\dd\yyyy", "31/12/" &
Year(Date))
EmpId = .Emplid
strDep = .Department
Reason = .ReasonForOvertime
WrkDate = .WorkDate
W0Prs = .Wrk0Prosent
W50Prs = .Wrk50Prosent
W100Prs = .Wrk100Prosent
W133Prs = .Wrk133Prosent
'Realz2 = .RealizeTo
TmeStp = .Registered
.Wrk50Prosent = 0
.Wrk100Prosent = 0
.Wrk133Prosent = 0
.Wrk0Prosent = (.Until - .From) * 24
If Me.Dirty = True Then Me.Dirty = False
If (MsgBox("You chose " & .RealizeTo.Text & "." & vbCrLf & _
"Bla, bla --some text bla....." & vbCrLf & vbCrLf & _
"Bla, bla --some text bla....." & vbCrLf & _
"Bla, bla --some text bla......", vbCritical + vbYesNo, _
"Overtime hours")) = vbYes Then
rs.Open "myTableName", CurrentProject.Connection,
adOpenKeyset, adLockOptimistic
rs.AddNew
rs("EmployeeId") = EmpId
rs("WorkDate") = WrkDate
rs("From") = "00:00" 'dtmFrom
rs("Until") = "00:00:00" 'dtmUntil
rs("Wrk0Prosent") = W0Prs
rs("Wrk50Prosent") = W50Prs
rs("Wrk100Prosent") = W100Prs
rs("Wrk133Prosent") = W133Prs
rs("RealizeTo") = 5 'Realz2
rs("TimeStamp") = TmeStp
rs("ReasonForOvertime") = Reason
rs("DateToRealize") = DateSerial(Year(Date), Month(Date) +
1, 15)
rs("User") = fGetUserName
rs("Department") = strDep
rs.Update
.Requery
End If
End If
End With
End Sub
... and this works fine for my purpose. (The calculations are very complex
and resides in
an other function and event. I won't include them here).
Well, hope somebody can use this code snippet if they turn into same
problem.
Anyway, thank you for your helping, Steve S. I was stuck for a while.. :)
Jan T.
"Steve Sanford" <limbim53 at yahoo dot com> skrev i melding
news: XXXX@XXXXX.COM ...