office交流网--QQ交流群号

Access培训群:792054000         Excel免费交流群群:686050929          Outlook交流群:221378704    

Word交流群:218156588             PPT交流群:324131555

从数据表中获取部门的函数

2020-01-19 08:00:00
zstmtony
原创
2759
Public Function GetDeptCodeLen(Optional rintLv As Integer = 0) As Integer
    Dim strTmp As String
    Dim arrPar() As String
    Dim i As Integer, j As Integer
    strTmp = DLookup("FSysParaValue", "tblZstmParameter", "FSysParaName='DeptLvLen'")
    arrPar = Split(strTmp, "/")
    If rintLv <> 0 Then
        GetDeptCodeLen = CInt(arrPar(rintLv - 1))
    Else
        j = 0
        For i = 0 To UBound(arrPar)
            j = j + CInt(arrPar(i))
        Next
        GetDeptCodeLen = j
    End If
    Erase arrPar
End Function

Private Sub FShift_AfterUpdate()
    Dim strShift As String
    Dim intDeptCodeLen As Integer

    intDeptCodeLen = GetDeptCodeLen
 
    If Nz(FShift) <> "" Then
       FShift = UCase(Nz(FShift))
       strShift = Right(Nz(FShift), 1)
       Me.FDeptCode = DLookup("FDeptCode", "tblHrmDept", "FDeptCode='" & Left(FShift, intDeptCodeLen) & "'")
       Select Case strShift
           Case "0", "1", "2"
             FCadreRank.Value = "員工"
           Case "3"
             FCadreRank.Value = "後勤"
           Case "4"
             FCadreRank.Value = "班長"
           Case "5"
             FCadreRank.Value = "組長"
           Case "6"
             FCadreRank.Value = "課長"
           Case "7"
             FCadreRank.Value = "廠長/協理"
           Case "8"
             FCadreRank.Value = "總經理"
           Case Else
             FCadreRank.Value = ""
       End Select
       'If Nz(FWorkKind) = "" Then
        FWorkKind = Nz(FCadreRank)
       'End If

       FDeptId.Value = GetDeptName(Nz(FDeptCode.Value))
    End If
End Sub

Public Function GetDeptName(ByVal rDeptCode As String) As String
    Dim strTmp As String
    Dim arrPar() As String
    Dim strDeptId As String
    Dim i As Integer, j As Integer
    If Trim(rDeptCode) = "" Then Exit Function
    strTmp = DLookup("FSysParaValue", "tblZstmParameter", "FSysParaName='DeptLvLen'")
    arrPar = Split(strTmp, "/")
    j = 0
    For i = 0 To UBound(arrPar)
         If CInt(arrPar(i)) <> 0 Then
             j = j + CInt(arrPar(i))
             strDeptId = strDeptId & " / " & Nz(DLookup("FDeptName", "tblHrmDept", "FDeptCode='" & Left(rDeptCode, j) & "'"))
         End If
    Next
    GetDeptName = Mid(strDeptId, 4)
       
    Erase arrPar
End Function
分享