Consulting

Results 1 to 14 of 14

Thread: Solved: Richardall: Form Field

  1. #1
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location

    Solved: Richardall: Form Field

    Posted on behalf of Richardall by firefytr.

    I would like to make a form field that holds a date. I would like the format to be mm/dd/yyyy.

    When you tab into the field, I would like a response box to ask "today" yes or no. If the answer is yes, I would like the field to be filled with today?s date. If no, I would like a drop down calendar to appear and the date can be chosen from that calendar. The chosen date will go in the field.

    Once filed in, the macro will set the date to the mentioned format, will tab to the next field and exit.

    Any help or suggested code would be greatly appreciated.

    Richard

  2. #2
    VBAX Expert xCav8r's Avatar
    Joined
    May 2005
    Location
    Minneapolis, MN, USA
    Posts
    912
    Location
    A form like in Word or a VB UserForm?

  3. #3
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Hi Zack & Richard,

    This can be done with a calendarcontrol on a userform.

    In a codemodule:[VBA]
    Option Explicit
    Public sName As String
    Sub CheckDate()
    sName = vbNullString
    sName = Selection.Bookmarks(1).Name

    If MsgBox("Insert today", vbYesNo + vbQuestion, "Insert Date") = vbYes Then
    ActiveDocument.FormFields(sName).Result = Date
    Else
    frmCalendar.Show
    End If

    ActiveDocument.FormFields(sName).Next.Select
    End Sub
    [/VBA]

    In the UserForm[VBA]
    Option Explicit
    Private Sub Calendar1_Click()
    ActiveDocument.FormFields(sName).Result = Calendar1.Value
    Unload Me
    End Sub
    Private Sub cmdClose_Click()
    Unload Me
    End Sub
    Private Sub UserForm_Initialize()
    Calendar1.Value = Date
    End Sub
    [/VBA]

    The mask in the formfield will take care of the desired date format.

    See attachment.

    Enjoy!
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

  4. #4
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    You need to make a reference to MSCAL.OCX to use the Calendar control. It is not a standard reference.

  5. #5
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Quote Originally Posted by fumei
    You need to make a reference to MSCAL.OCX to use the Calendar control. It is not a standard reference.
    Hi Gerry,

    True..I didn't mention that because Zack asked for a calander control so I figured he knows...

    But you're right I should mention these things..
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

  6. #6
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    Quote Originally Posted by MOS MASTER
    ..I didn't mention that because Zack asked for a calander control so I figured he knows...
    I do not need to know personally. This question was originally posted as an Article by Richardall and I thought it belonged in the Word forum. So I posted what he wrote (copy/paste) and pm'd the user.

  7. #7
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Quote Originally Posted by firefytr
    I do not need to know personally. This question was originally posted as an Article by Richardall and I thought it belonged in the Word forum. So I posted what he wrote (copy/paste) and pm'd the user.
    Thanx for clearing the matter..

    I thought Richard was a friend of yours or something...it was kinda unusual...

    So Ok Richard...did the code help you?
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

  8. #8

    Thank you to all for the help.

    Yes, the suggestions helped and after a little playing, the form is working and off to help a coworker. Thank you for all the help and suggestions.

    If I could ask one mor question, why doens't this work on a Mac? I sent the file to 5 peolple with different versions of word and the only persone that couldn't get it to work was the mac user.

    Please suggest a fix?

    Regards,
    Richard

  9. #9
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Hi Richard,

    You're most welcome.

    I think it doesn't work on the mac (Guess cause I don't own a mac) because it doesn't have or support MSCAL.OCX (Part of Access Installation)

    Did you check if it was there and properly registerd?

    We have 2 MAC wizards over here Blue Cactus & Shades. I sugest you mark this thread solved and post the document and your question over at the Mac questions part of this site.

    I'm sure they can help you..I'm just guessing!

    Later..
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

  10. #10

    Thanks again

    I would like to post the thread as closed but the pull-down isn't shown.

    I get three options, printable version, email this page and subscripbe to thread.

    Am I doing something wrong? I'm loged in.

    Richard

  11. #11
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Hi Richard,

    That's strange but it has happened before..

    I'll Ask one of the Admins to do it for you and look at your profile if they perhaps can find the cause of your problem.

    Later..
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

  12. #12
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    Richard

    What browser are you using?

  13. #13

    I think I figured it out.

    I didn't actually start the post. Firefytr posted it for me because I'm new and put it in the wrong place. I think he has the ability to close it.

    I opened a new thread and in that one, I have the ability to close.

    I think Firefytr will need to click the close button?

    Richard

  14. #14
    Administrator
    VP-Knowledge Base VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Hi Richard,

    You're absolutly right!
    I totally forgot about that. (It is a unusual situation)

    Glad to see it does work for you. BTW Jake allready marked the thread solved..

    Tada..
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

Posting Permissions

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