?
Solved

Re-Caption Command Buttons on New Form Instance

Posted on 2012-08-12
7
Medium Priority
?
336 Views
Last Modified: 2012-08-14
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.
0
Comment
Question by:dgheck
  • 4
  • 3
7 Comments
 
LVL 29

Expert Comment

by:IrogSinta
ID: 38285677
Can you post your code that this pertains to?
0
 

Author Comment

by:dgheck
ID: 38285683
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
 
LVL 29

Expert Comment

by:IrogSinta
ID: 38285698
Can you post your code that creates another instance of this form?
0
Transaction-level recovery for Oracle database

Veeam Explore for Oracle delivers low RTOs and RPOs with agentless transaction log backup and transaction-level recovery of Oracle databases. You can restore the database to a precise point in time, even to a specific transaction.

 
LVL 29

Expert Comment

by:IrogSinta
ID: 38285903
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
 

Author Comment

by:dgheck
ID: 38288270
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
 
LVL 29

Accepted Solution

by:
IrogSinta earned 2000 total points
ID: 38290275
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
 

Author Closing Comment

by:dgheck
ID: 38293169
Bingo! That works. Thanks.
0

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then reading…
Windows Explorer let you handle zip folders nearly as any other folder: Copy, move, change, and delete, etc. In VBA you can also handle normal files and folders, but zip folders takes a little more - and that you'll find here.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Suggested Courses
Course of the Month13 days, 16 hours left to enroll

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question