Results 1 to 7 of 7

Thread: combobox with msgbox in excel

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2011
    Posts
    1

    Question combobox with msgbox in excel

    hi! my userform has a combobox, and i would like to create a msgbox that when that combobox is blank or still has the phrase "Select Category..." will create a msgbox stating that the form is incomplete..

    this is my code do far:

    If cboCategory = "Select Category..." Then
    MsgBox "All Fields are Required!"
    Else
    End If

    This code is fine cause when i hit the OK button, the msgbox appears but the information typed in the other txtbox(same userform) is entered in the active sheet. I like to have a code that WILL NOT enter the information stated in other textbox when the OK button is clicked.

    Please help!! Thanks a lot...

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: combobox with msgbox in excel

    Welcome to VBForums

    Thread moved from the 'Database Development' forum (which is for questions about SQL/tables/etc) to the 'Office Development/VBA' forum

  3. #3
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: combobox with msgbox in excel

    perhaps like
    vb Code:
    1. If cboCategory.text = "Select Category..." or cboCategory.text = "" Then
    2.     MsgBox "All Fields are Required!"
    3.     exit sub
    4. End If
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  4. #4
    PowerPoster kaliman79912's Avatar
    Join Date
    Jan 2009
    Location
    Ciudad Juarez, Chihuahua. Mexico
    Posts
    2,593

    Re: combobox with msgbox in excel

    It depends on many things, the two main being where in code is your validation, and where in your code do you put the value in a cell. If what you are doing (most likely) is to have the combobox directly connected to the cell via the LinkedCell property then don't, and handle its value (Cell(r,c)=txtWhatever.Value) after the OK button is pressed.

    hmm just noticed you say you have a user form. I believe textboxes in userforms do not have the LinkedCell property, so just handle the value after the validation has been done.
    More important than the will to succeed, is the will to prepare for success.

    Please rate the posts, your comments are the fuel to keep helping people

  5. #5
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: combobox with msgbox in excel

    hmm just noticed you say you have a user form. I believe textboxes in userforms do not have the LinkedCell property,
    judging by the name it is a combobox, not a textbox, which has a rowsource, but there is no indication if it is being used, looks like a submit commandbutton is to be used when all boxes are filled
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  6. #6
    PowerPoster kaliman79912's Avatar
    Join Date
    Jan 2009
    Location
    Ciudad Juarez, Chihuahua. Mexico
    Posts
    2,593

    Re: combobox with msgbox in excel

    The current control appears to be a combobox, But the value passed to the cell, OP stated it is a textbox. Never the less, the same principle stands.
    More important than the will to succeed, is the will to prepare for success.

    Please rate the posts, your comments are the fuel to keep helping people

  7. #7
    Hyperactive Member
    Join Date
    Jun 2009
    Location
    England!
    Posts
    364

    Re: combobox with msgbox in excel

    The check entry for the combobox needs to be placed before the code that submits the data to the active sheet, this way it checks that everything is good to go and if happy it will enter the data to the sheet.

Posting Permissions

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



Click Here to Expand Forum to Full Width