Results 1 to 6 of 6
  1. #1
    Join Date
    Nov 2011
    Posts
    413

    Unanswered: Popup Form SetDate Command Button

    Hi,I have a popup form which has the weekday command buttons on it.Named Monday Thru Friday.They work correctly in that after clicking on the correct button for the day of the week it then inputs the correct date on my form.I want the form on opening to go to the correct day of the week,i.e command button.What event code can I use to set this to make it go to the correct day of the week command button? Name of form is frmSetpaydate

    Thanks,
    Attached Thumbnails Attached Thumbnails frmSetpaydate.png  
    Last edited by Burrina; 11-26-11 at 23:44. Reason: Make Clearer.

  2. #2
    Join Date
    Jun 2011
    Location
    Inside your mind
    Posts
    297
    Loads of ways to do this...

    Easiest would be, adding an [Event Procedure] to the Form OnLoad event.

    Code:
    Private Sub Form_Load()
    
    Select Case Format(Now(), "dddd")
        Case "Monday"
            Me.Monday.SetFocus
        Case "Tuesday"
            Me.Tuesday.SetFocus
        Case "Wednesday"
            Me.Wednesday.SetFocus
        Case "Thursday"
            Me.Thursday.SetFocus
        Case "Friday"
            Me.Friday.SetFocus
        Case "Saturday"
            Me.Saturday.SetFocus
        Case "Sunday"
            Me.Sunday.SetFocus
        Case Else
            Me.Monday.SetFocus
    End Select
    
    End Sub
    That will check the day today, and set the focus to whichever day it is. If, for some mad reason, Access doesn't know what day it is, it'll set the focus to your 'Monday' control.

    The code is untested, but should work just fine.
    Looking for the perfect beer...

  3. #3
    Join Date
    Nov 2011
    Posts
    413

    frmSetpaydate

    Here is my error trying this code,what am I doing wrong?
    See attached.

    Thanks

    I have text boxes used to set the days of the week on the form as well,here is what they are.
    Textbox used to set date for Thursday (Name one format m/d/yy)
    and it goes on such as two three four five six seven for all 7 days of the week.
    Attached Thumbnails Attached Thumbnails CodeError.png  
    Last edited by Burrina; 11-28-11 at 13:11. Reason: Further Explanation

  4. #4
    Join Date
    Jun 2011
    Location
    Inside your mind
    Posts
    297
    You're either using 'Option Explicit' at the top of the code, instead of 'Option Compare', or no control called 'SetDate' exists on the form 'frmSetpaydate', or the control 'SetDate' isn't a Label, and therefore can't respond to the method '.Caption'.

    Either way, that doesn't look like my code.
    Looking for the perfect beer...

  5. #5
    Join Date
    Nov 2011
    Posts
    413

    Sorry,my rookie mistake

    I corrected as below and all is well with the world. UhOh!!! I need ONE more thing if you dont mind.How could I close this form without using the code and just input the date manually if need be?

    Option Compare Database




    Private Sub Form_Close()
    If SetDate.Caption = "Monday" Then
    Forms![TimeCards]![Time and Hours].Form![WorkDate] = SelectDate.Value
    End If
    If SetDate.Caption = "Tuesday" Then
    Forms![TimeCards]![Time and Hours].Form![WorkDate] = SelectDate.Value
    End If
    If SetDate.Caption = "Wednesday" Then
    Forms![TimeCards]![Time and Hours].Form![WorkDate] = SelectDate.Value
    End If
    If SetDate.Caption = "Thursday" Then
    Forms![TimeCards]![Time and Hours].Form![WorkDate] = SelectDate.Value
    End If
    If SetDate.Caption = "Friday" Then
    Forms![TimeCards]![Time and Hours].Form![WorkDate] = SelectDate.Value
    End If
    If SetDate.Caption = "Saturday" Then
    Forms![TimeCards]![Time and Hours].Form![WorkDate] = SelectDate.Value
    End If
    If SetDate.Caption = "Sunday" Then
    Forms![TimeCards]![Time and Hours].Form![WorkDate] = SelectDate.Value
    End If
    Forms!TimeCards![Time and Hours].Form!Hours.SetFocus
    DoCmd.Close acForm, "frmSetpaydate"

    End Sub
    Last edited by Burrina; 11-28-11 at 13:47. Reason: Just One More Thing

  6. #6
    Join Date
    Jun 2011
    Location
    Inside your mind
    Posts
    297
    Please you got it working!

    Not sure why you've got:

    Code:
    Forms!TimeCards![Time and Hours].Form!Hours.SetFocus
    In there though, unless it triggers a GotFocus() event on that control, or something similar.
    Looking for the perfect beer...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •