Results 1 to 8 of 8
  1. #1
    2 Star Lounger
    Join Date
    Nov 2002
    Location
    Mt. Olive, North Carolina, USA
    Posts
    170
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Passing a date (97)

    I would like to pass a date that the user would input, into a new record field when that field has the focus. I tried this code but it is looking for a macro that doesn't exist.

    Private Sub Command14_Click()
    On Error GoTo Err_Command14_Click
    Dim strdate As Date
    strdate = InputBox("What date do you want to use?", , Date)


    DoCmd.GoToRecord , , acNewRec
    Me.Dt.OnGotFocus = strdate
    Exit_Command14_Click:
    Exit Sub

    Err_Command14_Click:
    MsgBox Err.Description
    Resume Exit_Command14_Click

    End Sub

    What do I need to change??? <img src=/S/igiveup.gif border=0 alt=igiveup width=31 height=23>
    Thanks.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Passing a date (97)

    This code won't work, as you found. OnGotFocus is an event; what you are trying to do here is set the name of the OnGotFocus event handler of Dt to the date entered by the user.

    Your description of what you want to accomplish is not clear to me. Do you want the user to be prompted for a date when Dt gets the focus in a new record? If so, be aware that the user will be prompted each time Dt gets the focus in a new record, not just the first time. Or do you - as the code seems to imply - want to go to a new record and prompt the user for a date? In that case, there is no need for an OnGotFocus event handler.

    So please try to explain as clearly as possible what you want.

  3. #3
    2 Star Lounger
    Join Date
    Nov 2002
    Location
    Mt. Olive, North Carolina, USA
    Posts
    170
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Re: Passing a date (97)

    Hi Hans -
    I would like the user to press a button to add a new record(s).
    They would be prompted for a date.
    Either when the new record opens or when the dt field of the new record has the focus, the date from the input box would fill in. What is the best method - when you enter a new record or when the field gets the focus? The dt field is the second field on the form that gets filled in.
    After they have enter the information in the last field, they can either add more records or stop.
    Thanks for your help. <img src=/S/bubbles.gif border=0 alt=bubbles width=31 height=17>
    John

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Passing a date (97)

    But why would you like to prompt for a date? The user can enter a date in the text box itself; popping up an input box doesn't make it easier or more user-friendly. Moreover, by setting a date format on the text box bound to Dt, you get automatic data validation, whereas Inputbox doesn't have built-in validation, you'll have to provide it yourself.

    As an alternative, you could use the Calendar control, the Date/Time picker or a custom calendar form to make entering the date more user-friendly.

  5. #5
    2 Star Lounger
    Join Date
    Nov 2002
    Location
    Mt. Olive, North Carolina, USA
    Posts
    170
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Re: Passing a date (97)

    There would be many records that would be added each day with the same date and the date would not be the computer's system date. If they could just enter the date once when the user starts to enter the records, it would save a lot of typing of entering the date on each record.
    I have seen something about a calendar with the activex controls but have not tried to use it in anyway.
    Which do you think would be the best for my sitiuation? (and easiest???lol)
    Have a great week.
    John

  6. #6
    2 Star Lounger
    Join Date
    Sep 2001
    Location
    Wellington, Wellington, New Zealand
    Posts
    181
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Passing a date (97)

    Hi

    The attached shows how to use a popup calendar that does not use activex control. Its probably been posted many times in the forum.

    It may help with the issue on prompting for a date.

    Regards
    WTH
    Attached Files Attached Files

  7. #7
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Passing a date (97)

    WTH has posted a popup form you can use.

    Another tip: if the user has entered the date once, (s)he can press Ctrl+' (Ctrl+apostrophe) in the date field in subsequent records to copy the value from the previous record.

    It is also possible to have the date copied from the previous record automatically. See ACC: Fill Record w/Data from Prev. Record Automatically (95/97)

  8. #8
    2 Star Lounger
    Join Date
    Nov 2002
    Location
    Mt. Olive, North Carolina, USA
    Posts
    170
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Re: Passing a date (97)

    Many thanks to WTH and Hans. I have learned a lot reading this forum but I still have a long way to go. <img src=/S/cooked.gif border=0 alt=cooked width=50 height=46>
    Best Wishes to ALL,
    John

Posting Permissions

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