PDA

View Full Version : Solved: Combo Boxes



pico
11-29-2006, 07:30 AM
I equate a combo box value to a integer variable in my userform. If i leave the combo box field empty and equate i get run-time error 13. How can i get rid of this problem?

examaple code :

Dim Temp as integer

Temp=CmbBox1.value

moa
11-29-2006, 07:55 AM
Temp=int(CmbBox1.value) or Temp=val(CmbBox1.value). Can't remember which it is in VBA.

CmbBox1.value is a string.

Sorry, misread your post. Please ignore

CBrine
11-29-2006, 08:09 AM
Dim Temp as integer

Temp=iif(CmbBox1.value="",0,cmbBox1.value)


or

if len(cmbbox1.value)=0 then
temp = 0
else
temp = cmbbox1.value
End if


HTH
Cal

malik641
11-29-2006, 08:11 AM
Hi pico,

moa's code would work, particularly:


Temp=val(CmbBox1.value)


If it is empty it will default to 0.

Or you could do a preliminary check to see if there's any text in the combo box to begin with:

If CmbBox1.Value <> "" Then Temp = CmbBox1.Value:thumb

Bob Phillips
11-29-2006, 08:55 AM
If CmbBox1.ListIndex = -1 Then
Temp = 0
Else
Temp = CmbBox1.Value
End If

pico
11-29-2006, 09:12 AM
Thank you All