P
PayeDoc
Hello All
I have a particular set of conditions, and an action (SendJmail) that
involve a combination of data held in tables, and runtime user responses. I
need to apply this same set of conditions and action to 5 different
'higher-level' actions - i.e. depending on the data/user resonses I need to
perform 1 of 5 actions (there are in fact 4 different combinations of
data/user resonses under which the action should be performed), and there
are 5 buttons on my form corresponding to each. Currently, the OnClick event
procedures behind each of the 5 buttons is almost identical - except for the
final 'higher-level' action (which appears 4 times, representing the 4
different combinations of data/user resonses under which the action should
be performed). The first of the 5 event procedures is below, into which I
have added 4 comments
'higher-level' action here:
to show where this happens.
So far, so good ... and it all works fine ... except that when I need to
update the set of conditions or the SendJmail action I have to do it 5
times. I think I should be writing the conditions and action as a seperate
function, or procedure, or something, that I could then call for each of the
5 'higher-level' actions, but I'm just not sure how to do this. The main
thing I don't understand is whether it should be a Function, or a Public
Function, or a Private Sub, and then also what - if anything - should follow
the Function, Public Function, or Private Sub declaration (as parameters?).
The 5 buttons for the 5 'higher-level' actions are all on the form [staffs
subform new], from which the expressions in the conditions take certain
values, but I can't see how to get the Function (or Public Function or
Private Sub) to take these values.
I hope I haven't made all this sound too complicated for anyone to reply!!
Thanks for any help.
Leslie Isaacs
The first of the 5 event procedures is:
Dim stDocName As String
Dim stLinkCriteria As String
If IsNull([DOB]) Or IsNull([NI number]) Then
Dim missinginfo As String
If IsNull([DOB]) Then missinginfo = " date of birth."
If IsNull([NI number]) Then missinginfo = " National Insurance number."
If IsNull([NI number]) And IsNull([DOB]) Then missinginfo = " date of
birth or National Insurance number."
MsgBox ("We do not have a record of this employee's" & [missinginfo])
If Not IsNull(DLookup("", "[practices]", "[prac name] =
[Forms]![staffs subform new]![practice]")) Then
If MsgBox("Do you want to send an email requesting this
information?", vbYesNo + vbQuestion, "WARNING") = vbYes Then
SendJmail _
DLookup("[email]", "[practices]", "[prac name] = [Forms]![staffs
subform new]![practice]"), _
[Forms]![staffs subform new]![practice], _
"[email protected]", _
[Forms]![staffs subform new]![practice] & " - P45 information",
_
"Hello " & DLookup("[prac mgr calling name]", "[practices]",
"[prac name] = [Forms]![staffs subform new]![practice]") _
& vbLf & vbLf & "We need to send a P45(1) for " &
[Forms]![staffs subform new]![Text544] & _
" to HMRC, but we do not have a record of " & [Forms]![staffs
subform new]![possesivepronoun] & [missinginfo] & _
" As this information is now mandatory for P45s, please could
you let us have the information as soon as possible." & vbLf & _
vbLf & "Kind regards" & vbLf & [Forms]![frm x main]![Combo687] &
vbLf & "PayeDoc"
MsgBox ("Email sent!")
End If
Else
MsgBox ("There is no email address for this Practice, so you'll have
to phone them!")
End If
Else
If [Forms]![staffs subform new]![Text531] & "" = "" Then
MsgBox ("This employee has no leaving date!")
Else
If CDate("1 " & DLookup("[months]![month name]", "[months]",
"[number]=DMax(""[x confirmed]![month number]"", ""[x confirmed]"",
""[name]=[forms]![staffs subform new]![text544]"")")) > [leaving date] Then
If MsgBox("This employee's last paid month is " &
DLookup("[months]![month name]", "[months]", "[number]=DMax(""[x
confirmed]![month number]"", ""[x confirmed]"", ""[name]=[forms]![staffs
subform new]![text544]"")") & ", but their leaving date is " & [leaving
date] & "." & vbNewLine & "Are you sure the P45 should include " &
DLookup("[months]![month name]", "[months]", "[number]=DMax(""[x
confirmed]![month number]"", ""[x confirmed]"", ""[name]=[forms]![staffs
subform new]![text544]"")"), vbYesNo) = vbYes Then
If [Forms]![staffs subform new]![Text531] < date - 30 Then
If MsgBox("This employee's leaving date is " &
[Forms]![staffs subform new]![Text531] & "." & vbNewLine & "Is this the
correct employee?", vbYesNo) = vbYes Then
' 'higher-level' action here:
stDocName = "frm_P45_submission"
DoCmd.OpenForm stDocName, , , stLinkCriteria
End If
Else
' 'higher-level' action here:
stDocName = "frm_P45_submission"
DoCmd.OpenForm stDocName, , , stLinkCriteria
End If
End If
Else
If [Forms]![staffs subform new]![Text531] < date - 30 Then
If MsgBox("This employee's leaving date is " & [Forms]![staffs
subform new]![Text531] & "." & vbNewLine & "Is this the correct employee?",
vbYesNo) = vbYes Then
' 'higher-level' action here:
stDocName = "frm_P45_submission"
DoCmd.OpenForm stDocName, , , stLinkCriteria
End If
Else
' 'higher-level' action here:
stDocName = "frm_P45_submission"
DoCmd.OpenForm stDocName, , , stLinkCriteria
End If
End If
End If
End If
I have a particular set of conditions, and an action (SendJmail) that
involve a combination of data held in tables, and runtime user responses. I
need to apply this same set of conditions and action to 5 different
'higher-level' actions - i.e. depending on the data/user resonses I need to
perform 1 of 5 actions (there are in fact 4 different combinations of
data/user resonses under which the action should be performed), and there
are 5 buttons on my form corresponding to each. Currently, the OnClick event
procedures behind each of the 5 buttons is almost identical - except for the
final 'higher-level' action (which appears 4 times, representing the 4
different combinations of data/user resonses under which the action should
be performed). The first of the 5 event procedures is below, into which I
have added 4 comments
'higher-level' action here:
to show where this happens.
So far, so good ... and it all works fine ... except that when I need to
update the set of conditions or the SendJmail action I have to do it 5
times. I think I should be writing the conditions and action as a seperate
function, or procedure, or something, that I could then call for each of the
5 'higher-level' actions, but I'm just not sure how to do this. The main
thing I don't understand is whether it should be a Function, or a Public
Function, or a Private Sub, and then also what - if anything - should follow
the Function, Public Function, or Private Sub declaration (as parameters?).
The 5 buttons for the 5 'higher-level' actions are all on the form [staffs
subform new], from which the expressions in the conditions take certain
values, but I can't see how to get the Function (or Public Function or
Private Sub) to take these values.
I hope I haven't made all this sound too complicated for anyone to reply!!
Thanks for any help.
Leslie Isaacs
The first of the 5 event procedures is:
Dim stDocName As String
Dim stLinkCriteria As String
If IsNull([DOB]) Or IsNull([NI number]) Then
Dim missinginfo As String
If IsNull([DOB]) Then missinginfo = " date of birth."
If IsNull([NI number]) Then missinginfo = " National Insurance number."
If IsNull([NI number]) And IsNull([DOB]) Then missinginfo = " date of
birth or National Insurance number."
MsgBox ("We do not have a record of this employee's" & [missinginfo])
If Not IsNull(DLookup("", "[practices]", "[prac name] =
[Forms]![staffs subform new]![practice]")) Then
If MsgBox("Do you want to send an email requesting this
information?", vbYesNo + vbQuestion, "WARNING") = vbYes Then
SendJmail _
DLookup("[email]", "[practices]", "[prac name] = [Forms]![staffs
subform new]![practice]"), _
[Forms]![staffs subform new]![practice], _
"[email protected]", _
[Forms]![staffs subform new]![practice] & " - P45 information",
_
"Hello " & DLookup("[prac mgr calling name]", "[practices]",
"[prac name] = [Forms]![staffs subform new]![practice]") _
& vbLf & vbLf & "We need to send a P45(1) for " &
[Forms]![staffs subform new]![Text544] & _
" to HMRC, but we do not have a record of " & [Forms]![staffs
subform new]![possesivepronoun] & [missinginfo] & _
" As this information is now mandatory for P45s, please could
you let us have the information as soon as possible." & vbLf & _
vbLf & "Kind regards" & vbLf & [Forms]![frm x main]![Combo687] &
vbLf & "PayeDoc"
MsgBox ("Email sent!")
End If
Else
MsgBox ("There is no email address for this Practice, so you'll have
to phone them!")
End If
Else
If [Forms]![staffs subform new]![Text531] & "" = "" Then
MsgBox ("This employee has no leaving date!")
Else
If CDate("1 " & DLookup("[months]![month name]", "[months]",
"[number]=DMax(""[x confirmed]![month number]"", ""[x confirmed]"",
""[name]=[forms]![staffs subform new]![text544]"")")) > [leaving date] Then
If MsgBox("This employee's last paid month is " &
DLookup("[months]![month name]", "[months]", "[number]=DMax(""[x
confirmed]![month number]"", ""[x confirmed]"", ""[name]=[forms]![staffs
subform new]![text544]"")") & ", but their leaving date is " & [leaving
date] & "." & vbNewLine & "Are you sure the P45 should include " &
DLookup("[months]![month name]", "[months]", "[number]=DMax(""[x
confirmed]![month number]"", ""[x confirmed]"", ""[name]=[forms]![staffs
subform new]![text544]"")"), vbYesNo) = vbYes Then
If [Forms]![staffs subform new]![Text531] < date - 30 Then
If MsgBox("This employee's leaving date is " &
[Forms]![staffs subform new]![Text531] & "." & vbNewLine & "Is this the
correct employee?", vbYesNo) = vbYes Then
' 'higher-level' action here:
stDocName = "frm_P45_submission"
DoCmd.OpenForm stDocName, , , stLinkCriteria
End If
Else
' 'higher-level' action here:
stDocName = "frm_P45_submission"
DoCmd.OpenForm stDocName, , , stLinkCriteria
End If
End If
Else
If [Forms]![staffs subform new]![Text531] < date - 30 Then
If MsgBox("This employee's leaving date is " & [Forms]![staffs
subform new]![Text531] & "." & vbNewLine & "Is this the correct employee?",
vbYesNo) = vbYes Then
' 'higher-level' action here:
stDocName = "frm_P45_submission"
DoCmd.OpenForm stDocName, , , stLinkCriteria
End If
Else
' 'higher-level' action here:
stDocName = "frm_P45_submission"
DoCmd.OpenForm stDocName, , , stLinkCriteria
End If
End If
End If
End If