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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Working with Instances of same form

Status
Not open for further replies.

DariceLR

MIS
Jun 20, 2001
27
US
Situation:
I have a form that inputs records to a database. When I want to put in information found in a supporting table, I use a Modal form to search the table (on SQL Server 7) and move the information found in the search results back to the original form. After querying the supporting table, I move the information from the grid of search results found to the fields the user inputs their search requirements to and when the Modal form is closed, it sends the foreign information to the fields it needs to go in.

Problem:
When I close the form, it should take information from the current form and move it back into the original form. As seen in the below code, I get a new instance of the form with the information I wanted in it instead of the instance of the form that originally called the saved within the record I am creating.

Code:
Private Sub cmdOk_Click()
    'What do I do to pull the information out of the data grid?
    'The following line of code makes the new instance of the form "frmNewRequest"
    'one instance of form
    frmNewRequest.txtDeveloperSSN = "102938838"
    'two instances of form
    'Closes Form... and opens a new request... don't want that...
    Me.Hide
    'Unload Me
End Sub

Question(s):
How do I reference different instances of the form?
How can I tell which instance is which?
How do I tell the form which instance I want filled in?

(I thought ActiveForm may be of use in the MDI but I must not know how to use it or it didn't like how I used it)

(Thanks in advance!) ****************
DariceLR
:-{} :-V :-x
****************
 
You may want treat your forms like any other object...

In your calling (or parent form) add something like:

Private Sub Command1_Click()
Dim strSSN As String
Dim objNewRequest As MyForm

Set objNewRequest = New MyForm

objNewRequest.Text1 = "12345678" 'Initialize any data
for this instance of
the form

objNewRequest.Show vbModal

'If we've made it here then the OK button has
'been clicked or window was closed in instance of MyForm

'Get data from instance of MyForm

strSSN = objNewRequest.Text1

Set objNewRequest = Nothing 'destroy the instance

End Sub


In your query form, in this case MyForm, add the following:

Private Sub cmdOk_Click()
Me.Hide
End Sub

Of course you need to add a command button named 'cmdOk'

 
So what your saying is that kind of pass the data in reverse? So that the calling form pulls the data instead of the called form pushing the data back? Or am I to use the object idea on the called form?

****************
DariceLR
:-{} :-V :-x
****************
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top