Convidado 15/7/2011, 22:31
Substitua o código por este e resolve este problema.
Private Sub txt_rf_AfterUpdate()
If IsNull(Me.txt_rf.Value) Or Me.txt_rf.Value = "" Then
MsgBox "O campo RF está vazio!", vbCritical + vbOKOnly, "Atenção!"
Me.txt_aviso.Visible = False
Me.txt_aviso.BorderStyle = 0
Me.txt_aviso.Caption = ""
Me.foto.Visible = False
Me.foto = ""
ElseIf Not IsNumeric(Me.txt_rf.Value) Then
MsgBox "Insira apenas números!", vbCritical + vbOKOnly, "Atenção!"
Me.txt_rf.Value = Null
Me.txt_aviso.Visible = False
Me.txt_aviso.BorderStyle = 0
Me.txt_aviso.Caption = ""
Me.foto.Visible = False
Me.foto = ""
End If
Dim sql As String
Dim rst As Recordset
sql = "SELECT * FROM funcionario WHERE cd=" & Me.txt_rf.Value
Set rst = CurrentDb.OpenRecordset(sql)
If IsNull(DLookup("[cd]", "funcionario", "[cd]=" & Me!txt_rf)) Then
MsgBox "Registro não encontrado !", vbOKOnly + vbCritical, "Atenção"
Me.txt_rf.Value = ""
Exit Sub
Else
Me.txt_aviso.Visible = True
Me.txt_aviso.BorderStyle = 0
Me.txt_aviso.Caption = rst!nm_funcionario
Me.foto.Visible = True
Me.foto = rst!foto
End If
If MsgBox("CLICK EM OK OU TECLE ENTER PARA CONFIRMAR!", vbOKCancel, "REGISTRAR PONTO") = vbOK Then
If IsNull(DLookup("[entrada1]", "controle_ponto", "[cd]=" & Me!txt_rf & " and pontodata= #" & Format(Date, "mm/dd/yyyy") & "#")) Then
DoCmd.SetWarnings False 'desativa a exibição de mensagens do sistema
DoCmd.RunSQL "INSERT INTO controle_ponto (cd,entrada1,pontodata) select " & Me.txt_rf & ",#" & Time & "#, #" & Format(Date, "mm/dd/yyyy") & "#"
DoCmd.SetWarnings True 'ativa a exibição de menssagens do sistema
Me.txt_rf.Value = Null
Me.txt_aviso.Visible = False
Me.txt_aviso.BorderStyle = 0
Me.txt_aviso.Caption = ""
Me.foto.Visible = False
Me.foto = ""
ElseIf IsNull(DLookup("[saida1]", "controle_ponto", "[cd]=" & Me!txt_rf & " and pontodata= #" & Format(Date, "mm/dd/yyyy") & "#")) Then
DoCmd.SetWarnings False 'desativa a exibição de mensagens do sistema
DoCmd.RunSQL "UPDATE controle_ponto set saida1=#" & Time & "# where cd= " & Me.txt_rf & " and pontodata= #" & Format(Date, "mm/dd/yyyy") & "#"
DoCmd.SetWarnings True 'ativa a exibição de menssagens do sistema
Me.txt_rf.Value = Null
Me.txt_aviso.Visible = False
Me.txt_aviso.BorderStyle = 0
Me.txt_aviso.Caption = ""
Me.foto.Visible = False
Me.foto = ""
ElseIf IsNull(DLookup("entrada2", "controle_ponto", "cd=" & Me!txt_rf & " and pontodata= #" & Format(Date, "mm/dd/yyyy") & "#")) Then
DoCmd.SetWarnings False 'desativa a exibição de mensagens do sistema
DoCmd.RunSQL "UPDATE controle_ponto set entrada2= #" & Time & "# where cd= " & Me.txt_rf & " and pontodata= #" & Format(Date, "mm/dd/yyyy") & "#"
DoCmd.SetWarnings True 'ativa a exibição de menssagens do sistema
Me.txt_rf.Value = Null
Me.txt_aviso.Visible = False
Me.txt_aviso.BorderStyle = 0
Me.txt_aviso.Caption = ""
Me.foto.Visible = False
Me.foto = ""
ElseIf IsNull(DLookup("saida2", "controle_ponto", "cd=" & Me!txt_rf & " and pontodata= #" & Format(Date, "mm/dd/yyyy") & "#")) Then
DoCmd.SetWarnings False 'desativa a exibição de mensagens do sistema
DoCmd.RunSQL "UPDATE controle_ponto set saida2= #" & Time & "# where cd= " & Me.txt_rf & " and pontodata= #" & Format(Date, "mm/dd/yyyy") & "#"
DoCmd.SetWarnings True 'ativa a exibição de menssagens do sistema
Me.txt_rf.Value = Null
Me.txt_aviso.Visible = False
Me.txt_aviso.BorderStyle = 0
Me.txt_aviso.Caption = ""
Me.foto.Visible = False
Me.foto = ""
End If
Else
Me.txt_rf.Value = Null
Me.txt_aviso.Visible = False
Me.txt_aviso.BorderStyle = 0
Me.txt_aviso.Caption = ""
Me.foto.Visible = False
Me.foto = ""
Exit Sub
End If
Set rst = Nothing
End Sub
Saudações