Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Label caption not changing.

Status
Not open for further replies.

Lammers

Programmer
Sep 5, 2001
12
0
0
HK
Simple and yet frustrating.
I've got a form (FORM1) which opens amodal form via a button.

User enters some value into the modal form and clicks OK, which calls a sub on FORM1 and changes a label on FORM1.
However, this label on FORM1 never changes.
I've seen this before, but can't remember how to fix this.

CODE:

FORM1
=====
Public Sub Change_Label1(ByVal str As String)
Me.Label_Dest_Info.Caption = str
Me.Label_Dest_Info.Refresh
End Sub

Private Sub Command_Dest_Click()
Set fSomeForm = New theForm
fSomeForm.Show 1
End Sub


Modal theForm
==========
Private Sub cmdOK_Click()
...
...
FORM1.Change_Label1 "CHANGE ME!!"
...
unload me
end sub

 
I just put the code you did

Form1 (form) has the following controls
Label_Dest_Info (label)
Command_Dest (command button)
Code:
Public Sub Change_Label1(ByVal str As String)
    Me.Label_Dest_Info.Caption = str
    Me.Label_Dest_Info.Refresh
End Sub

Private Sub Command_Dest_Click()
    Dim fSomeForm As theForm
    Set fSomeForm = New theForm
    fSomeForm.Show 1
End Sub

theForm (form) has the following control
cmdOK (command button)
Code:
Private Sub cmdOK_Click()
Form1.Change_Label1 "CHANGE ME!!"
Unload Me
End Sub

Start the program and hit the command button on Form1
theForm loads
press the command buttons on theForm (cmdOK) and the label's (label_Dest_Info) caption on Form1 changes


Some notes Change_Label1 isn't needed and if it does it is missleading on multiple levels.
1) could be confused with the labels actual Change event which gets the proceedure name of LabelName_Change.
2) the name above would lead me to think the name of the label is actually Label1 but your code works on Label_Dest_Info

Some other notes. Your command buttons names are not consistant. One form you prefix the control name with Command_ (Command_Dest) in theForm you prefix it with cmd (cmdOK) the latter is the most used standard.


Given what you provided via code (see my code) the application does exactly what you said it won't so we need more info on what you are doing.

I suspect you may be instancing Form1 somewhere and theForm code is actually either working on a hidden Form1 or a new Form1 that is not being shown.

First thing I'd try is this
Code:
Private Sub cmdOK_Click()
Form1.Change_Label1 "CHANGE ME!!"
Form1.Show
Unload Me
End Sub


Hope I've been helpful,
Wayne Francis

If you want to get the best response to a question, please check out FAQ222-2244 first
 
Hi.

I don't understand what the problem is.

You successfully written 7 lines of redundent code

Why not just say

label1.caption = str

Try this on for size

Create 1 label on your form.
Create 1 Command Button on your form.
Leave the names as default names.

Now copy and paste this code:

Dim Str1 as String
Dim Str2 as String

private Sub Form_Load()
Str1 = "Hello"
Str2 = "Bye"
Label1.Caption = Str1
end sub

private sub command1_click()
if label1.caption = Str1 then
Label1.Caption = Str2
Else
Label1.Caption = Str1
End If
end Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top