ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Getting text string into userform (https://www.excelbanter.com/excel-programming/414952-getting-text-string-into-userform.html)

salgud

Getting text string into userform
 
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.

RB Smissaert

Getting text string into userform
 
Try instead Label1.Caption

RBS


"salgud" wrote in message
.. .
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.



salgud

Getting text string into userform
 
On Thu, 31 Jul 2008 21:55:44 +0100, RB Smissaert wrote:

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?

RB Smissaert

Getting text string into userform
 
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

"salgud" wrote in message
...
On Thu, 31 Jul 2008 21:55:44 +0100, RB Smissaert wrote:

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?



salgud

Getting text string into userform
 
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?

RB Smissaert

Getting text string into userform
 
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


"salgud" wrote in message
...
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?



JLGWhiz

Getting text string into userform
 
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


"salgud" wrote:

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?


salgud

Getting text string into userform
 
On Thu, 31 Jul 2008 18:04:01 -0700, JLGWhiz wrote:

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


"salgud" wrote:

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?


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.

salgud

Getting text string into userform
 
On Thu, 31 Jul 2008 23:31:24 +0100, RB Smissaert wrote:

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


"salgud" wrote in message
...
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?


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


All times are GMT +1. The time now is 05:13 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com