Set Focus not working after calling a function

sgtSortor

Registered User.
Local time
Today, 12:54
Joined
Mar 23, 2008
Messages
31
I have a database that tracks equipment being reserved, checked out, check in and cancelled………
When I am entering a date for when someone will bring back a piece of equipment. The system checks to see if it’s a weekend or holiday and goes back to that field so a correct date can be entered if it is a weekend or holiday.
Everything works great, except it won’t go back to the correct field. It always goes back to the first field on the form. There are only 6 fields on this form,
cboSelectCustomer, cboDDO , cboTDO, cboDDI , cboTDI, cboWhere
The scenario I am testing is for equipment going out today and coming back another day.
cboSelectCustomer
cboDDO=11/21/2014
cboTDO = 2:28 PM
cboDDI = 11/22/2014 (weekend) so system tells me it’s a weekend, clears the field and should put the cursor back into this field. Unfortunately the cursor alwys goes back to “cboSelectCustomer”

All the fields are set to Tab Stop=No
I’ve tried beforeupdate and couldn’t get it to work there either.
Code:
Private Sub cboDDI_AfterUpdate()
Dim vDate As Date
Forms!frmhold.DDIHold = Me.cboDDI
vDate = Me.cboDDI
Forms!frmhold.DDIHold = Me.cboDDI
Call OfficeClosed(vDate)
    If Forms!frmhold.HolidayWeekend = "Holiday" Or Forms!frmhold.HolidayWeekend = "Weekend" Then
        Me.cboDDI = ""
        Me.cboDDI.SetFocus
    End If
End Sub

Code:
Function OfficeClosed(vDate) As Integer
Dim vHoliday
   ' Test for Saturday or Sunday.
  '  MsgBox Weekday(vDate)
   If Weekday(vDate) = 1 Or Weekday(vDate) = 7 Then
    MsgBox "That date is a weekend, select another date!"
    Forms!frmhold.HolidayWeekend = "Weekend"
    Exit Function
   Else
    Forms!frmhold.HolidayWeekend = ""
   End If
    If Weekday(vDate) = 2 Or Weekday(vDate) = 3 Or Weekday(vDate) = 4 Or Weekday(vDate) = 5 Or Weekday(vDate) = 6 Then
        vHoliday = DLookup("Holiday", "ltblHolidays", "[HolidayDate]= # " & vDate & "#")
            If Not IsNull(DLookup("HolidayDate", "ltblHolidays", "[HolidayDate]=#" & vDate & "#")) Then
                  MsgBox "That date is " & vHoliday & ", select another date!"
            End If
        Forms!frmhold.HolidayWeekend = "Holiday"
    Else
        Forms!frmhold.HolidayWeekend = ""
    End If
End Function

Any help appreciated.
 
I think you have a logic issue. Your test for a holiday would still run for a weekend date, and the Else clause in that sets the form field to "".
 

Users who are viewing this thread

Back
Top Bottom