+ Reply to Thread
Results 1 to 14 of 14

Combo Box date format also to accept text

Hybrid View

  1. #1
    Registered User
    Join Date
    10-06-2010
    Location
    Dunstable,England
    MS-Off Ver
    Excel 2010
    Posts
    95

    Combo Box date format also to accept text

    Hi I have a form with several combo boxes. The combo boxes are programmed to only accept a time format from the drop down list. But i alse have to alow the user to select either start or finish as a text option.


    the code I have so far is

    Private Sub FriFinish1_Change()
        Static Disabled As Boolean
        If Disabled Then Exit Sub
        Disabled = True
        FriFinish1.Value = Format(Val(FriFinish1.Value), "hh:mm")
        Disabled = False
            
    End Sub

    I have added the text options to the drop down, but when they are selected the program crashes and foes into debug mode. Does anyone know of a way to prevent this. The only text I want the user to select is start or finish.

    Many thanks
    Nods
    Last edited by nods; 11-18-2010 at 06:28 PM.

  2. #2
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,985

    Re: Combo Box date format also to accept text

    What error are you getting and where?
    Everyone who confuses correlation and causation ends up dead.

  3. #3
    Registered User
    Join Date
    10-06-2010
    Location
    Dunstable,England
    MS-Off Ver
    Excel 2010
    Posts
    95

    Re: Combo Box date format also to accept text

    The user has a list to select from:

    Start
    00:00
    00:15
    00:30

    If the user slects start it breaks and goes into debug mode because it isn't in the hh:mm format.

    My question is is there a way of being able to set a combo box to display the hh:mm format and the word start?

    Many thanks

  4. #4
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,985

    Re: Combo Box date format also to accept text

    I repeat, What error are you getting and where?

  5. #5
    Registered User
    Join Date
    10-06-2010
    Location
    Dunstable,England
    MS-Off Ver
    Excel 2010
    Posts
    95

    Re: Combo Box date format also to accept text

    I'm not in front of the work book but was on this peice of code bin the change control of the combo box. It is because it is set to hh:mm format I need it to be able to also accept the word 'Finish'.

    Private Sub FriFinish1_Change()
        Static Disabled As Boolean
        If Disabled Then Exit Sub
        Disabled = True
        FriFinish1.Value = Format(Val(FriFinish1.Value), "hh:mm")
        Disabled = False
            
    End Sub

  6. #6
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,985

    Re: Combo Box date format also to accept text

    That code should not cause an error for text.

  7. #7
    Registered User
    Join Date
    10-06-2010
    Location
    Dunstable,England
    MS-Off Ver
    Excel 2010
    Posts
    95

    Re: Combo Box date format also to accept text

    Apologies, it broke to the debug when I was trying this peice of code with the error "type mismatch."



     FriFinish1.Value = Format(Val(FriFinish1.Value), "Finish", "hh:mm")
    With out the "Finish" it just displays 00:00 when Finish is selected.

    Kind regards

    Nods

  8. #8
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,985

    Re: Combo Box date format also to accept text

    "Finish" is not a valid format code, and you can't supply two format codes. It also didn't appear in any of the code you posted!
    If you are supplying the list to the combo, I suggest you put the two text values first (or last) and then check the listindex before formatting the value, though I'm not entirely sure why you need to format the values anyway.

  9. #9
    Registered User
    Join Date
    10-06-2010
    Location
    Dunstable,England
    MS-Off Ver
    Excel 2010
    Posts
    95

    Re: Combo Box date format also to accept text

    If I don't Format the values as time they just appear as decimal numbers. The text field is already in the list index and appears in the drop down menu on the combobox, it is just that when the text field is selected it is displayed as 00:00.

  10. #10
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,985

    Re: Combo Box date format also to accept text

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

  11. #11
    Registered User
    Join Date
    10-06-2010
    Location
    Dunstable,England
    MS-Off Ver
    Excel 2010
    Posts
    95

    Re: Combo Box date format also to accept text

    It is bound using row source!

  12. #12
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,985

    Re: Combo Box date format also to accept text

    Don't use the RowSource. Assign the range's value to the list property of the combo at runtime (Initialize event of the form).

  13. #13
    Registered User
    Join Date
    10-06-2010
    Location
    Dunstable,England
    MS-Off Ver
    Excel 2010
    Posts
    95

    Re: Combo Box date format also to accept text

    Thanks I have look at that forum. It looks like i would need to write the list in the event for all combo boxes. I have alot of comboboxes and the list is also long.

    would be a hell of a lot of code.

  14. #14
    Registered User
    Join Date
    10-06-2010
    Location
    Dunstable,England
    MS-Off Ver
    Excel 2010
    Posts
    95

    Re: Combo Box date format also to accept text

    Just for inforamtion I have solved the problem with the below code.

    Thanks for your help.


    Private Sub FriFinish1_Change()
        
        If FriFinish1.Value = "Finish" Then
        Exit Sub
        End If
        
        Static Disabled As Boolean
        If Disabled Then Exit Sub
        Disabled = True
      
        FriFinish1.Value = Format(Val(FriFinish1.Value), "hh:mm")
    
        Disabled = False
      
        End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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