Phalanx
Phalanx

Reputation: 1217

Excel - VBA : Userform.Label won't change

My VBA program processes some operations on an input typed by the user and eventually gives back a result.

At some point, I want to have some userform showing up and "adjusting" the research. For example, if the user typed a state and a city which doesn't fit, it would show "Did you mean city in state ? ". Then, clicking on yes would take into account the modification, clicking no wouldn't change anything.

I have tried this, as found in some tutorials :

city = sMain.Range("J12").Value
province = sMain.Range("J6").Value
provinceSugg = sCurrent.Cells(p, db_column).Value

If province = "" And city <> "" Then
UserForm2.Show
UserForm2.Label1 = "Do you mean : " & city & " in " & provinceSugg
Else
End If

Unfortunately, it doesn't work at all, whatever text I write for Label1 and whatever way of writing I use (Label1.Caption = , Userform2.Label1.Caption = , Label1 = , etc.), still no change.

Thanks for helping me to fix this !

Upvotes: 0

Views: 9241

Answers (2)

matzone
matzone

Reputation: 5719

Use vbModeless ..

If province = "" And city <> "" Then
  UserForm2.Show vbModeless
  UserForm2.Label1 = "Do you mean : " & city & " in " & provinceSugg
Else

End If

Upvotes: 1

sous2817
sous2817

Reputation: 3960

Set the caption before showing the form...like this:

city = sMain.Range("J12").Value
province = sMain.Range("J6").Value
provinceSugg = sCurrent.Cells(p, db_column).Value

If province = "" And city <> "" Then
UserForm2.Label1 = "Do you mean : " & city & " in " & provinceSugg
UserForm2.Show
Else
End If

Upvotes: 1

Related Questions