user2835653 user2835653 - 1 year ago 71 Question

Use Copies of Forms

i have a form that pulls in data, crunches numbers, does things. it works perfectly.

the problem is the code is i can only access one market at a time and i want to have the ability to access more than one.

i could duplicate the current form x 4 let's say, so then after i login i could have access to 4 markets, instead of 1. but the code is a little dense, and i would be stuck with however many forms i have hardwired, instead of having the flexibility to replicate the initial form, and then access another market.

the simplest and fastest way to accomplish this would be to use some code that would 'pop-up' a clone of the existing form, if such a thing is possible.

Answer Source

If I understand what you are after, you want something like this (first part is VERY similar to "Michael's" answer):

In the form:

Public MarketCOde As String        ' whatever it is.

Public Sub New(mktCode As String)
   ' leave this line alone

   MarketCOde = mktCode
End sub

Now anywhere the code in your form needs to know which market it is working on, it can reference MarketCode.

To create a form to work with a new market:

 Dim frmAsia As New FORMNAME("ASIA")

Since the form will REQUIRE a market code, we are passing it when we create the form. We arent cloning the form, but creating an instance of it to work with different, but specific, markets. Now, keep reading because here is the bad news:

If all the code is embedded in the form, it will have to be refactored to reference MarketCode instead of the hardcoded references likely there now. Next, your app needs a new way to start since the mainform wont get that critical MktCode arg from VB.

The best thing is to add a market picker form, and make that the start up form in Project Properties. Add buttons to create each new market form you need:

' this is a new button on a new form to make Market Form instances.
Sub button1_click......

  ' USE THE ACTUAL FormName from your code!
  Dim frmCentral as New FORMNAME("CENTRAL")   

 End Sub

' each button makes a new market form,
Sub button2_click......                     ' NOTE: Btn 2!

  ' the FormName from your code
  Dim frmAsia as New FORMNAME("ASIA")   

 End Sub

One button, one form instance name, one market

This is also the startup form to launch the first one. Be sure to set it as the startup form In Project Properties.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download