|
-
Aug 6th, 2011, 11:48 PM
#1
Thread Starter
New Member
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...
-
Aug 7th, 2011, 09:44 AM
#2
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
-
Aug 8th, 2011, 04:00 AM
#3
Re: combobox with msgbox in excel
perhaps like
vb Code:
If cboCategory.text = "Select Category..." or cboCategory.text = "" Then MsgBox "All Fields are Required!" exit sub 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
-
Aug 8th, 2011, 08:21 AM
#4
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
-
Aug 8th, 2011, 03:54 PM
#5
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
-
Aug 8th, 2011, 04:09 PM
#6
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
-
Aug 12th, 2011, 09:54 PM
#7
Hyperactive Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|