+ Reply to Thread
Results 1 to 11 of 11

Thread: Combobox - Date format problem

  1. #1
    Registered User
    Join Date
    06-07-2010
    Location
    Blantyre, Malawi
    MS-Off Ver
    Excel 2003
    Posts
    20

    Question Combobox - Date format problem

    Hi,
    I have a Combobox in a form (cmbDate) that looks up a list of dates from a sheet formatted (dd/mm.yy)
    When I select a date it displays correctly but when I select a date from the list it then converts it to a number and saves it in that format.

    Ive tried to format the combobox using the following code:

    Me.cmbDate.value= Format (me.cmbDate.value, "dd/mm/yy")

     Me.cmbDate.value= Format (me.cmbDate.value, "dd/mm/yy")
    
    I've also tried 
    
    Me.cmbDate.date= Format (me.cmbDate.date, "dd/mm/yy")
    Neither works. In first case I get error "Wrong number of arguments or invalid property assignment" with the word "Format" highlighted. In second case I get error "Method or data member not found": with the second ".Date" highlighted.

    All I need to do is to be able to format the combobox field so that when it reads or writes a value it will be in the correct format.

    I suspect I'm going to have the same issue with my amounts (number) fields
    Regards,

    Alan

  2. #2
    Forum Moderator dominicb's Avatar
    Join Date
    01-25-2005
    Location
    Lancashire, England
    MS-Off Ver
    MS Office 2000, 2003 & 2007
    Posts
    3,714

    Smile Re: Combobox - Date format problem

    Good morning AlanAnderson

    What do you mean by "saves it in that format"? What are you doing with the date you select?

    One fo the problems with using VBA is that you lose certain formats, such as dates, the standard Microsoft preferred format is applied. Everytime you use your selection after that, you will need to re-specify its format. The format you apply to display it in the combobox will only make it look how you want - the underlying date data will be unchanged.

    HTH

    DominicB

  3. #3
    Registered User
    Join Date
    06-07-2010
    Location
    Blantyre, Malawi
    MS-Off Ver
    Excel 2003
    Posts
    20

    Re: Combobox - Date format problem

    Hi,

    Thanks for the response. I am looking up dates from a table (dd/mm/yy) The form is supposed to allow user to select one of the dates from the table. When user clicks on a date it is displayed on the form as a number eg 01/01/10 is displayed as 40179. I need it to display as dd/mm/yy and then, if edited, to be saved in the list as a date, not a number.

    Regards,

    Alan

  4. #4
    Forum Moderator dominicb's Avatar
    Join Date
    01-25-2005
    Location
    Lancashire, England
    MS-Off Ver
    MS Office 2000, 2003 & 2007
    Posts
    3,714

    Smile Re: Combobox - Date format problem

    Hi AlanAnderson

    When you say "form" are you referring to a UserForm?
    If so, how are you showing the date on the UserFrom - are you using a TextBox?

    DominicB

  5. #5
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    Apparently I can't say
    MS-Off Ver
    Apparently I can't say
    Posts
    8,274

    Re: Combobox - Date format problem

    Is your combobox bound to the worksheet using rowsource and/or controlsource?

  6. #6
    Registered User
    Join Date
    06-07-2010
    Location
    Blantyre, Malawi
    MS-Off Ver
    Excel 2003
    Posts
    20

    Re: Combobox - Date format problem

    Hi Dominic,

    No its a standard combobox called from the toolkit.

    Regards
    Alan

  7. #7
    Registered User
    Join Date
    06-07-2010
    Location
    Blantyre, Malawi
    MS-Off Ver
    Excel 2003
    Posts
    20

    Re: Combobox - Date format problem

    Hi Romperstomper,

    I used a line in my code stating:
    me.cmbDate.rowsource="A2:A" & FinalRow

    I hope that answers the question.

    Regards,

    Alan
    BTW "Romperstomper" sounds awfully like rugrat stamper - hope not

  8. #8
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    Apparently I can't say
    MS-Off Ver
    Apparently I can't say
    Posts
    8,274

    Re: Combobox - Date format problem

    First thing: don't bind controls to sheets. I suggest you use:
    me.cmbDate.List = Range("A2:A" & FinalRow).Value
    instead.
    Second thing: no, romperstomper is a film.

  9. #9
    Registered User
    Join Date
    06-07-2010
    Location
    Blantyre, Malawi
    MS-Off Ver
    Excel 2003
    Posts
    20

    Re: Combobox - Date format problem

    Hi All,
    Still have problem.

    I have tried use of DTPicker which seems to do what I need. I just have concern about distributing programme to other machines. Will this be a problem?

    Regards,

    Alan

  10. #10
    Forum Guru, retired Admin royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    25,639

    Re: Combobox - Date format problem

    DatePicker will be a problem if the end user does not have the control on their machine, & Excel 2010 does not support them. See alternatives in the addins section here
    Hope that helps.

    RoyUK
    --------
    If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need

    For Excel Tips & Solutions, free examples and tutorials why not check out my downloads

    New members please read & follow the Forum Rules

    Remember to mark your questions Solved and rate the answer(s)

  11. #11
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    Apparently I can't say
    MS-Off Ver
    Apparently I can't say
    Posts
    8,274

    Re: Combobox - Date format problem

    Does the combo in the attached work for you?
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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.2.0