dgheck
asked on
Re-Caption Command Buttons on New Form Instance
I have a form for which I have created the ability to open multiple instances and it works well except for one problem. The form has several command buttons, the captions for which are written upon the form opening by looking into a table, retrieving the value and writing the caption.
THE PROBLEM: It works properly only on the original instance of the form. When I open any multiple form instance after that the captions don't get written to the command buttons.
The Sub to write the proper captions is located in the frmModule. What is preventing it from working when I open another instance of the form?
Thanks for any help.
THE PROBLEM: It works properly only on the original instance of the form. When I open any multiple form instance after that the captions don't get written to the command buttons.
The Sub to write the proper captions is located in the frmModule. What is preventing it from working when I open another instance of the form?
Thanks for any help.
Can you post your code that this pertains to?
ASKER
Yes, thank you. This is the Sub in the form's code module that re-captions the command buttons:
Private Sub LoadCommandButtonCaptions( )
Dim strCurrentForm As String
strCurrentForm = Me.Form.Name
Dim strButtonCaption As String
Dim strButtonName As String
Dim strControlName As String
Dim intNext As Integer
Dim strNext As String
For intNext = 1 To 42
strNext = Format(intNext, "0#")
strButtonName = "cmd_ptb_REM" & strNext
strControlName = "frmCurrent!" & strButtonName
strButtonCaption = GetButtonCaption(strButton Name)
With Forms(strCurrentForm).Cont rols(strBu ttonName)
.SetFocus
.Caption = strButtonCaption
End With
Next intNext
End Sub
(Please forgive any inelegance in my coding, I am new at this and self-taught.)
Private Sub LoadCommandButtonCaptions(
Dim strCurrentForm As String
strCurrentForm = Me.Form.Name
Dim strButtonCaption As String
Dim strButtonName As String
Dim strControlName As String
Dim intNext As Integer
Dim strNext As String
For intNext = 1 To 42
strNext = Format(intNext, "0#")
strButtonName = "cmd_ptb_REM" & strNext
strControlName = "frmCurrent!" & strButtonName
strButtonCaption = GetButtonCaption(strButton
With Forms(strCurrentForm).Cont
.SetFocus
.Caption = strButtonCaption
End With
Next intNext
End Sub
(Please forgive any inelegance in my coding, I am new at this and self-taught.)
Can you post your code that creates another instance of this form?
If you declare a Form object at the module level and then use that to create another instance of the form, you can then use your form variable to refer to your buttons. For instance, at the top of your form module, you could declare Dim frmNew as Form Then you would create another instance of your form this way:
frmNew.btnNameOfButton.Cap tion = GetButtonCaption(strButton Name)
Set frmNew = New Form_NameOfYourForm
frmNew.SetFocus
Then you can refer to your controls this way:frmNew.btnNameOfButton.Cap
ASKER
I am still unclear as to the proper locations for the code snippets.
Here is the code contained in the Form's Module to write the captions to the Command Buttons:
Private Sub LoadCommandButtonCaptions( )
Dim strCurrentForm As String
strCurrentForm = "frm_add_edit_instrument"
Dim strButtonCaption As String
Dim strButtonName As String
Dim strControlName As String
Dim intNext As Integer
Dim strNext As String
For intNext = 1 To 42
strNext = Format(intNext, "0#")
strButtonName = "cmd_ptb_REM" & strNext
strControlName = "frmCurrent!" & strButtonName
strButtonCaption = GetButtonCaption(strButton Name)
'With frmNew
With Forms(strCurrentForm).Cont rols(strBu ttonName)
.SetFocus
.Caption = GetButtonCaption(strButton Name)
End With
Next intNext
End Sub
And here is the code in a Standard Module that opens the new form instance:
ublic Function OpenFormInstance(FormName As String, Optional WhereCondition As String)
'Declare the Form Name
Dim frmNew As Form
Set frmNew = New Form_frm_add_edit_instrume nt
If WhereCondition <> "" Then
frmNew.Filter = WhereCondition
frmNew.FilterOn = True
End If
'Make the Form Visible
frmNew.Visible = True
'Alter Form's Caption
'Need to add a reference to the form so it doesn't immediately close when the form variable goes out of scope
mcolFormInstances.Add frmNew
End Function
Hope this assists you in helping me out. Thank you in advance for any time spent on this.
Here is the code contained in the Form's Module to write the captions to the Command Buttons:
Private Sub LoadCommandButtonCaptions(
Dim strCurrentForm As String
strCurrentForm = "frm_add_edit_instrument"
Dim strButtonCaption As String
Dim strButtonName As String
Dim strControlName As String
Dim intNext As Integer
Dim strNext As String
For intNext = 1 To 42
strNext = Format(intNext, "0#")
strButtonName = "cmd_ptb_REM" & strNext
strControlName = "frmCurrent!" & strButtonName
strButtonCaption = GetButtonCaption(strButton
'With frmNew
With Forms(strCurrentForm).Cont
.SetFocus
.Caption = GetButtonCaption(strButton
End With
Next intNext
End Sub
And here is the code in a Standard Module that opens the new form instance:
ublic Function OpenFormInstance(FormName As String, Optional WhereCondition As String)
'Declare the Form Name
Dim frmNew As Form
Set frmNew = New Form_frm_add_edit_instrume
If WhereCondition <> "" Then
frmNew.Filter = WhereCondition
frmNew.FilterOn = True
End If
'Make the Form Visible
frmNew.Visible = True
'Alter Form's Caption
'Need to add a reference to the form so it doesn't immediately close when the form variable goes out of scope
mcolFormInstances.Add frmNew
End Function
Hope this assists you in helping me out. Thank you in advance for any time spent on this.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Bingo! That works. Thanks.