View Full Version : Solved: Combo Boxes
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
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
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.