Results 1 to 3 of 3
  1. #1
    2 Star Lounger
    Join Date
    Jun 2003
    Location
    Indiana, USA
    Posts
    141
    Thanks
    2
    Thanked 0 Times in 0 Posts
    I have form with a subform. Works great. Subform is "continuous" and is use to track employee information. On the form is a field [Date]. In the subform "header" is a button for setting a 'Default Date", so that the same date does not need to be entered over and over for multiple employees.

    Code for button:

    Private Sub cmdSetDefDate_Click()
    Dim Prompt As String
    Dim Answer
    Prompt = "Please enter the default date, (example: 5/6/09), for the records you are about to input."
    Answer = InputBox(Prompt, "Default Date Input")
    lblDefaultDate.Caption = Answer

    'Date.Value = CDate(Answer)
    'cmbEmpName.SetFocus

    If Answer = "" Then
    cmbEmpName.SetFocus
    Else
    Date.Value = CDate(Answer)
    cmbEmpName.SetFocus
    End If
    End Sub


    After you enter the date in the InputBox, the date is captured in the [lblDefaultDate] field. When you press the ok button on the InputBox, the date autofills the [Date] field in my subform. If the InputBox is not used, the the default value for the [lblDefaultDate] displays "Default Date".

    On the subform, the [Date] field has a default value set to:

    =IIf([lblDefaultDate].[Caption]="Default Date","",CDate([lblDefaultDate].[Caption]))

    Entering the date in the InputBox actually enters the date in 2 records on my subform. The one with the * bside it, and the one with the pen. So far everything works great. However...when I complete the 1st record and begin the 2nd new (subform) record, the [Date] field no longer autofills the date value set in the [lblDefaultDate] field. The date is still there, but does not carry through to the subform.

    I have tried to point the default value of [Date] to include the subform name (=IIf([SUBFORMNAME].[lblDefaultDate].[Caption]=...) but that did not work either.

    I am sure that there is something obvious (and simple) that I am missing. I appreciate any input and assistance provided.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    Try the following. You won't need the label for this, and you don't have to set the default value of Date in design view.

    Code:
    Private Sub cmdSetDefDate_Click()
      Dim Prompt As String
      Dim Answer
      Prompt = "Please enter the default date, (example: 5/6/09), for the records you are about to input."
      Answer = InputBox(Prompt, "Default Date Input")
    
      If IsDate(Answer) Then
    	Me!Date.Value = Answer
    	Me!Date.DefaultValue = Chr(34) & Answer & Chr(34)
      End If
      cmbEmpName.SetFocus
    End Sub

  3. #3
    2 Star Lounger
    Join Date
    Jun 2003
    Location
    Indiana, USA
    Posts
    141
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Hans, thanks, that works great. I do need to write a code to "clean" that date when moving to the next or new records. It is carrying the date information over. But I think I can figure that one out.

    Thanks again.

Posting Permissions

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