Getting text string into userform

S

salgud

I'm working on a program that needs a text string to show in the label in a
userform. I got some help with it, but the code he gave me doesn't work,
and I've never seen it done this way before, so I can't figure out what is
wrong. This is the code I was given, which is in the userform. I'm not even
sure that's where it's supposed to go.

Sub UserForm1_Initialize()
Dim sMsg As String
sMsg = "The client " & sTRID & " is not in the datbase." _
& vbCrLf & "Do you want to add them?"

Label1.Text = sMsg <----- Method or data member not found

End Sub

I'm getting a Method or data member not found on the ".Text" portion. Does
anyone know what's wrong? The variable "sTRID" is publicly declared in the
module.

Thanks in advance.
 
S

salgud

Try instead Label1.Caption

RBS
Thsnks for your reply. That's a step in the right direction. It compiles
and runs now. But I'm still not getting the text string as the label in the
userform. It just shows "Label1". I want it to show that text with the
string variable "sTRID" in it. Any suggestions?
 
R

RB Smissaert

Does it actually run? Test by putting a Msgbox before
your line where the label gets set.
Did you put it in the right userform?
Does the label get set somewhere else in your code?
Does it work if you specify a much smaller bit of text?

RBS
 
S

salgud

On Thu, 31 Jul 2008 22:31:28 +0100, RB Smissaert wrote:
Thanks for the help.
Does it actually run? Yes.
Test by putting a Msgbox before
your line where the label gets set.
I tried one after the label got set. If the label isn't set, the MsgBox
can't show it either. It worked.
Did you put it in the right userform?
Only one.
Does the label get set somewhere else in your code? Nope.
Does it work if you specify a much smaller bit of text?
Tried that, didn't work either.
Any other ideas?
 
R

RB Smissaert

Can't think of much else now. It works fine with me.
If the label isn't set, the MsgBox can't show it either. It worked.

Not sure what you are saying here. Did you see the message box popping up?

Are there any non-default properties of that label?
Try removing that label and try with a new one?
How about taking Label1 out of the Caption property box?


RBS
 
J

JLGWhiz

Well, I don't know what to tell you. I created a UserForm, put a label on it
and put the code below in the initialize event of the form. I had to give
sTRID a phony value but the message appeared as the caption of the label when
I called the form from the standard module with the UserForm1.Show method.
There was a typo in my original snippet where I used Private Sub
UserForm1_Initialize. The one does not belong there for this usage. Sorry
about that. Try pasting the code below, as is, into the UserForm code window
and see if you still get the error message.

Private Sub UserForm_Initialize()
Dim smsg As String
smsg = "The client " & sTRID & " is not in the datbase." _
& vbCrLf & "Do you want to add them?"
Me.Label1.Caption = smsg
End Sub
 
S

salgud

Well, I don't know what to tell you. I created a UserForm, put a label on it
and put the code below in the initialize event of the form. I had to give
sTRID a phony value but the message appeared as the caption of the label when
I called the form from the standard module with the UserForm1.Show method.
There was a typo in my original snippet where I used Private Sub
UserForm1_Initialize. The one does not belong there for this usage. Sorry
about that. Try pasting the code below, as is, into the UserForm code window
and see if you still get the error message.

Private Sub UserForm_Initialize()
Dim smsg As String
smsg = "The client " & sTRID & " is not in the datbase." _
& vbCrLf & "Do you want to add them?"
Me.Label1.Caption = smsg
End Sub

Thanks! This worked great. I had put in "Userform1" because that's the
userform's name is. I guess that's just one of those weird VBA things you
have to know somehow. Don't use the userform's actual name, just use
"userform".

Got it fixed and I learned another of the many anomalies in VBA.
 
S

salgud

Can't think of much else now. It works fine with me.


Not sure what you are saying here. Did you see the message box popping up?

Are there any non-default properties of that label?
Try removing that label and try with a new one?
How about taking Label1 out of the Caption property box?


RBS

Thanks for the help, got it fixed. If curious, see below.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top