Private Sub 证件号码_AfterUpdate()
Dim Cd As Integer '定义“长度”变量:Cd
Dim Nian, Yue, Re, Xb As String '定义 "年"、 “月”、“ 日”、“性别”变量
Cd = Len(证件号码)
If Cd = 18 Then
Nian = Mid(证件号码, 7, 4)
Yue = Mid(证件号码, 11, 2)
Re = Mid(证件号码, 13, 2)
Xb = Mid(证件号码, 17, 1)
ElseIf Cd = 15 Then
Nian = "19" & Mid(证件号码, 7, 2)
Yue = Mid(证件号码, 9, 2)
Re = Mid(证件号码, 11, 2)
Xb = Mid(证件号码, 15, 1)
Else
MsgBox "您输入的身份证号有误!长度应为15位或者18位,但实际长度为:" & Cd
Exit Sub
End If
出生日期 = Nian & "年" & Yue & "月" & Re & "日"
Xb = Xb Mod 2
If Xb = 1 Then
性别.Value = "男"
Else
性别.Value = "女"
End If
End Sub