UserForm Labels "0" return

C

CrankyLemming

Hi

I hope I can explain this okay.

I have a userform which contains several labels whose captions are
taken from various cells on a sheet, activated by a 'Details' command
button.

The trouble is, not every is used every time. For example, the cells
have address line 1, line 2, line 3, postcode, phone number, fax
number; in cases where there isn't a fax number, I'm getting the
return "0".

I've tried to remedy this by putting the following code in the
("Details")button_click event:

For Each cntrl In UserForm1.Controls
If TypeOf cntrl Is MSForms.Label And Caption = "0" Then
Caption = ""

End If

.... but am still getting the zero return. Basically, I want the label
to be 'empty' or blank on screen if there is no data to fill it.

Am I missing something really obvious?

TIA

Steve
 
P

papou

Hi
For Each cntrl In UserForm1.Controls
If TypeOf cntrl Is MSForms.Label And cntrl.Caption = "0" Then
cntrl.Caption = ""

End If

HTH
Cordially
Pascal
 
H

Harald Staff

Hi Steve

Show the code that takes the cell values and put them on the labels. Better
prevent it there than clean up afterwards.

Problem with your code displayed is that Caption doesn't point to anything.

HTH. Best wishes Harald
 
C

CrankyLemming

Harald said:
Show the code that takes the cell values and put them on the labels. Better
prevent it there than clean up afterwards.

Not sure what you mean here. The code for the CommandButton_Click is

Worksheets("AllCont").Activate
Range("W4").Select
ActiveCell.Value = ComboBox2.Value
Label4.Caption = Sheets("AllCont").Range("w5")
Label5.Caption = Sheets("AllCont").Range("w6")
[----more lines like this---]

For Each cntrl In UserForm12.Controls
If TypeOf cntrl Is MSForms.Label And Caption = "0" Then
Caption = ""

End If

I've tried putting this last bit in the form activate and in the
'Workbook Open' module (?), and nada. The source cell for these label
captions are the results of a VLookup function, and I've tried to use
IF to say if there's no return, blank the cell - the result is the
'0'.
Problem with your code displayed is that Caption doesn't point to anything.

....but the lines above clear that up, don't they?

Thanks for your help, Harald.

Steve
 
C

CrankyLemming

papou said:
For Each cntrl In UserForm1.Controls
If TypeOf cntrl Is MSForms.Label And cntrl.Caption = "0" Then
cntrl.Caption = ""

End If

Thanks Pascal, but this didn't work either. Even with a 'Next' line added :)

Steve
 
C

CrankyLemming

Harald said:
Show the code that takes the cell values and put them on the labels. Better
prevent it there than clean up afterwards.

Have now worked it out. Thanks again, Harald.

steve
 
Top