Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Got Focus not working.

Status
Not open for further replies.

Razor1

IS-IT--Management
Nov 21, 2002
81
US
This should be simple but it is not working. The set focus does not go to the end date field after the message. Whats wrong?

Thanks in advancefor any and all help.





If Me!EndDate > rs!PAyDate Then

lngRetval = MsgBox( _
"The date is not included in the Payroll History Table. You may need to Run an update to Payroll History Table. " & vbCrLf & "" & vbCrLf & "Check date or see the payroll administrator.", _
vbOKOnly + vbCritical + vbDefaultButton1, _
"ERROR ! - ")

Select Case lngRetval
Case vbOK
Me!EndDate.SetFocus
End Select
End If

Razor1
 
You cannot set the focus to a field that already has the focus. Which event are you using? If you use the Before update event of EndDate, then Cancel=True should suit.
 
Thanks for the quick response. I am not sure I understand how/where Ishould use the cancel.


Razor1
 
Which event are you using? Please post your code from Sub... to ...End Sub.
 
Here is the code:

Private Sub EndDate_AfterUpdate()
Dim db As Database
Dim rs As Recordset
Dim lngRetval As Long
Dim strMessage As String

Set db = CurrentDb
Set rs = db.OpenRecordset("qry_OldestPD")
rs.MoveFirst

strMessage = "The date is not included in the Payroll History Table. " & vbCrLf & vbCrLf & _
"You may need to Run an update to Payroll History Table." & vbCrLf & vbCrLf & _
"Check date or see the payroll administrator." & vbCrLf & vbCrLf & _
"The oldest date in the History Table is " & rs!PAyDate

If Me!EndDate > rs!PAyDate Then

lngRetval = MsgBox(strMessage, vbCritical, "Date Error!!")

Select Case lngRetval
Case vbOK
Me!StartDate.SetFocus
Me!EndDate.SetFocus
End Select
End If
rs = Nothing
db = Nothing

End Sub

Razor1
 
Try using the Before update event:

Code:
Private Sub EndDate_BeforeUpdate(Cancel As Integer)
    Dim db As Database
    Dim rs As Recordset
    Dim lngRetval As Long
    Dim strMessage As String
                    
    Set db = CurrentDb
    Set rs = db.OpenRecordset("qry_OldestPD")
    rs.MoveFirst
    
    strMessage = "The date is not included in the Payroll History Table. " & vbCrLf & vbCrLf & _
                "You may need to Run an update to Payroll History Table." & vbCrLf & vbCrLf & _
                "Check date or see the payroll administrator." & vbCrLf & vbCrLf & _
                "The oldest date in the History Table is " & rs!PAyDate
    
    If Me!EndDate > rs!PAyDate Then
        
        MsgBox(strMessage, vbCritical, "Date Error!!")
        Cancel=True    
    
    End If
    rs = Nothing
    db = Nothing
    
End Sub
 
That worked..Thanks...Have a star.

Razor1
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top