Re- Set Focus After Calendar Form Call

scouser

Registered User.
Local time
Today, 23:45
Joined
Nov 25, 2003
Messages
767
Hello guys. Mile-0 has been advising me regards implementing a calendar into my forms. The Calendar works great. However I have one small glitch regards returning the focus to a control on the main form. Basically I click a cmd and the caledar form opens. I select a date from the calendar form then click either cmdConfirm or cmdCancel. Either way I would like the focus to return to a particular control on my main form. Why? I have validation etc.....When I tabbed after closing the calendar form a new record was being generated.
A way round this was to set the 'Cycle' value to Current Record. This works but is not ideal as the user has to then tab through loads of fields to get back to the date!! Right, now forgive the monster code I am about to post, but you can never have enough info (right?). All the code below is thanks to Mile-0, bar the stuff that doesn't work for which I will take full credit! Ha! Ha!
Here Goes: And the winner is.....
Code:
Module:
Option Compare Database
Public Function IsFormOpen(strFormName As String) As Boolean
    IsFormOpen = (SysCmd(acSysCmdGetObjectState, acForm, strFormName) = acObjStateOpen)
End Function
and then......
Code:
Private Sub cmdConfirm_Click()

    Dim dteSelected As Date ' for storing the selected date
    
    ' store user's selected value
    dteSelected = Me.ctlCalendar.Value
    ' ******************************
    ' * insert calendar rules here *
    ' ******************************    
    ' In this section you can define all of the rules for your calendar.
    ' If multiple forms call this calendar then you can set rules for it
    ' here using SELECT CASE statements. You can also use this structure
    ' to set different rules for different controls on the same form.
    '
    ' An example of setting a property would be:
    '
    '       cal.AllowSundays = False
    ‘ which would ensure that if the user selected a date where the day was
    ' a Sunday then that date would not be selected.
    
  [COLOR=DarkRed]
‘ My code is here
  
    If IsFormOpen("fmrEnquiries") Then
    Forms!frmEnquiries!ConfirmedServiceDate.SetFocus

    Else
    If IsFormOpen("fmrOrders") Then
    Forms!frmOrders!ConfirmedServiceDate.SetFocus
    End If
    End If[/COLOR]    ' Also included is the HasRange property (boolean) which can be set to True
    ' Once this is set to True, you will also need to set the RangeStart and RangeEnd
    ' properties too, defining a range in which the calendar form will accept dates for.
     ' ******************************
    ' *    end of calendar rules   *
    ' *****************************
    ' use the calendar class's Validate method to ensure that
    ' the date selected is allowed
    If cal.Validate(Me.ctlCalendar.Value) = False Then
        MsgBox mbMessage, mbType, mbTitle
        Exit Sub
    End If
    
    ' assign selected value to calling form's control
    Forms(strForm).Controls(strControl) = dteSelected
          
    ' close the calendar form
    DoCmd.Close acForm, Me.Name
   
End Sub
and finally......
[CODE]
Private Sub cmdCancel_Click()
' close the calendar form
    DoCmd.Close acForm, Me.Name

    If IsFormOpen("fmrEnquiries") Then

    Forms!frmEnquiries!ConfirmedServiceDate.SetFocus
    If IsFormOpen("fmrOrders") Then

    Forms!frmOrders!ConfirmedServiceDate.SetFocus
    End If
    End If
End Sub
[/CODE]

Pheew.................
Solution would be much appreciated!!
Phil. :(
 
Why don't you just put the code in the on close of the calendar (or along those lines)

Code:
Forms!frmOrders!ConfirmedServiceDate.SetFocus
________
SILVERSURFER VAPORIZER
 
Last edited:

Users who are viewing this thread

Back
Top Bottom