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.
dgheckAsked:
Who is Participating?
 
IrogSintaCommented:
Can you put the routine for the button captions within the OpenFormInstance routine so that you could use frmNew as a reference within each instance.  It would look like this:

frmNew(strButtonName).Caption = GetButtonCaption(strButtonName)
0
 
IrogSintaCommented:
Can you post your code that this pertains to?
0
 
dgheckAuthor Commented:
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(strButtonName)
   
        With Forms(strCurrentForm).Controls(strButtonName)
        .SetFocus
        .Caption = strButtonCaption
    End With
Next intNext
End Sub

(Please forgive any inelegance in my coding, I am new at this and self-taught.)
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
IrogSintaCommented:
Can you post your code that creates another instance of this form?
0
 
IrogSintaCommented:
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:
Set frmNew = New Form_NameOfYourForm
frmNew.SetFocus

Open in new window

Then you can refer to your controls this way:
frmNew.btnNameOfButton.Caption = GetButtonCaption(strButtonName)
0
 
dgheckAuthor Commented:
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(strButtonName)
        'With frmNew
        With Forms(strCurrentForm).Controls(strButtonName)
        .SetFocus
        .Caption = GetButtonCaption(strButtonName)
    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_instrument

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.
0
 
dgheckAuthor Commented:
Bingo! That works. Thanks.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.