简体   繁体   中英

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 !

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

Use vbModeless ..

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

End If

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM