ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   if then else problem (https://www.excelbanter.com/excel-programming/403073-if-then-else-problem.html)

Pierre[_18_]

if then else problem
 
Hi,

can anybody tell me what is wrong in this snippet of code ?

If search_acc.Value < " " Then
result = search_acc.Value
Column = 23
ElseIf search_status < " " Then
result = search_status.Value
Column = 176
Else: GoTo nochoice
End If
.....
various code
.....
nochoice:
msgbox "you did not make a choice, make a choice !"


Where search_acc and search_status are comboboxes
Whatever you do, you allways end up with the messagebox from nochoice:
Please help !
Thanks,
Pierre



Dan R.

if then else problem
 
Try using "" instead of " ".

--
Dan

On Dec 20, 12:44 pm, "Pierre" wrote:
Hi,

can anybody tell me what is wrong in this snippet of code ?

If search_acc.Value < " " Then
result = search_acc.Value
Column = 23
ElseIf search_status < " " Then
result = search_status.Value
Column = 176
Else: GoTo nochoice
End If
....
various code
....
nochoice:
msgbox "you did not make a choice, make a choice !"

Where search_acc and search_status are comboboxes
Whatever you do, you allways end up with the messagebox from nochoice:
Please help !
Thanks,
Pierre


JLGWhiz

if then else problem
 
Should This:
If search_acc.Value < " " Then
be this:
If search_acc.Value < "" Then

Unless you deliberately put the space between the double quotes for clarity
in this posting, it probably would not work well in your code unless you have
single spaces entered in your combobox. If you are testing for null then,
there should be no space between the quote marks.

Also, it is not good practice to use reserved names like Column for
variables. That can produce undesirable results too.

"Pierre" wrote:

Hi,

can anybody tell me what is wrong in this snippet of code ?

If search_acc.Value < " " Then
result = search_acc.Value
Column = 23
ElseIf search_status < " " Then
result = search_status.Value
Column = 176
Else: GoTo nochoice
End If
.....
various code
.....
nochoice:
msgbox "you did not make a choice, make a choice !"


Where search_acc and search_status are comboboxes
Whatever you do, you allways end up with the messagebox from nochoice:
Please help !
Thanks,
Pierre




Bill Renaud

if then else problem
 
What line of code do you have on the line immediately above the line label
"nochoice:"?

You should have an Exit Sub or something to make sure you jump around the
MsgBox. (I'm assuming that the MsgBox after "nochoice:" is right at the end
of the routine, like an error handler.)
--
Regards,
Bill Renaud




Bill Renaud

if then else problem
 
You also have the following line:

Else: GoTo nochoice

There should not be a colon (:) after the Else.

--
Regards,
Bill Renaud




Pierre[_18_]

if then else problem
 
Hi Bill,

stupid of me, it was indead the : (colon)
thanks for your help,
Pierre
"Bill Renaud" schreef in bericht
. ..
You also have the following line:

Else: GoTo nochoice

There should not be a colon (:) after the Else.

--
Regards,
Bill Renaud







All times are GMT +1. The time now is 02:14 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com