+ Reply to Thread
Results 1 to 4 of 4

Date format force Properties in VBA forms

  1. #1
    Registered User
    Join Date
    03-16-2016
    Location
    London
    MS-Off Ver
    2013
    Posts
    34

    Angry Date format force Properties in VBA forms

    Hey everyone

    I am setting up a database which has a number of date fields. Traditionally in the past a number of people have housed the wrong date, for example, I want dd/mm/yyyy however I attain results such as dd/mm/yy, d/mm/yyyy, dd.mm.yyyy or d.mm.yyyy. This is an issue as I have sub formulas running off these dates and need them consistent.

    How can I force the data base to accept only dates in the dd/mm/yyyy formats than can form part of routine to check and return error text to users whom are entering data in the wrong format.

    Thanks
    Michael

  2. #2
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: Date format force Properties in VBA forms

    Access is a database. Excel is a spreadsheet. Are you talking about a pseudo database in Excel?

    If Excel, your formulas should be using the data Value, not the date Format. As such, format the cells to the format that you want. If using Excel, you can delete invalid dates using the Worksheet's Change event. If you want to try that, say so. If they enter dd/mm/yy like 1/2/03, then you really have no way to correct that. It is the same as if they picked the wrong date from a calendar dialog. A Worksheet's Selection event could be used to open a date dialog. If you want that, say what worksheet and range the dates are in.

  3. #3
    Registered User
    Join Date
    03-16-2016
    Location
    London
    MS-Off Ver
    2013
    Posts
    34

    Re: Date format force Properties in VBA forms

    Hi Kenneth

    Yes, I'm using Excel to compile multiple responses in a database style format. I'm using a macro to collate the information. Once of the Macro fields it a text box to collect the date in a dd/mm/yyyy format, however I really don't want to trust the users that this is they will enter this correctly. Is there a way in VBA to change the properties of the cell so only the date format dd/mm/yyyy is permissible, thereby allowing the correct information to come through to drive other metrics?

    Thanks
    Michael

  4. #4
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: Date format force Properties in VBA forms

    As I said, you can determine if a string (textbox values are strings) is a date or impossible date. You can not determine if it is the "correct" date where 01/02/01 could be mm/dd/yy or dd/mm/yy. For cells, you could use a date format but it is still a number.

    You can do similar checks for a cell by adding a Worksheet Change event. You are better off using a date control or a pseudo date userform to make sure that they at least pick a valid date to begin with.

    If you are using a userform, we could add a date control activex control. The most reliable method if it is a one off deal is to use a pseudo date dedicated userform.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Force date validation in specified format
    By valcrist_m in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-16-2016, 09:30 PM
  2. Force Cell format as General when entering in a date.
    By Miskondukt in forum Excel General
    Replies: 2
    Last Post: 12-03-2015, 03:46 PM
  3. [SOLVED] force format date
    By pannam in forum Excel General
    Replies: 7
    Last Post: 10-20-2014, 03:44 AM
  4. [SOLVED] Trying to force a date format 'd-mmm-yy', not working.
    By tv69 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-20-2013, 03:47 PM
  5. Force macro to a date format. Used a userform instead
    By Philb1 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 10-16-2011, 05:30 AM
  6. Date format in VBA user-forms
    By ilovelagar in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 09-17-2009, 02:48 PM
  7. Force cell date format
    By Macdave_19 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-20-2007, 04:07 PM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1