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

How to passing a value from findform to main form

Status
Not open for further replies.

Vincentan

MIS
Aug 21, 2002
52
MY
Hello Guy,

recently I had create a form which allow to select the record by using data grid and I had to set the find method in main form, when I calling findform.show, the operation still be continue in main form even I had not finish choose the record.

How do this work around to passing the valid value back to main form after I found the record in findform?

My code is: (rsSQL is my Recordset and xLogCode contain a text which after complete frmFind operation)

frmFind.Show
rsSQL.Find "logcode = " & xLogCode
dspRECORD()

It's dosen't care whether I had get the record or not, the program still display record where the operation frmFind still not completed!

Please advice! [2thumbsup]
 
Vincentan,

Why don't you open the frmFind as a Dialog window

frmFind.ShowDialog()
rsSQL.Find "logcode = " & xLogCode
dspRECORD()

should solve your problem.

-Kris

 
Hi Kris! Thanks for this!

But i have no idea how to do this, for the showdialog() is not a form's class/ object method member, how to call this?

Can you show me? [sadeyes]
 
Vincentan,

ShowDialog is an Object(form) function. Everything is same as you are doing except that instead of calling .Show(), you will be using .ShowDialog(). The difference is that .ShowDialog will open the form as a response window and since it is a response window exceution will not regain control on the calling form unless and until you close the dialog window. Code will look like something as follows,

Dim ofrmMyForm As New frmMyForm()
ofrmMyForm.ShowDialog()

Let me know if you have any questions...

-Kris
 
hihihi It's come out Method or Data member not found when running th code even use your method?

It only accept objForm.Show and not accept the code for objForm.ShowDialog it show invalid! even I declare
Dim objForm As New frmFind

[ponder]
 
And by the way Kris, do you have any idea how to detect in the main form when the sub form been unloaded! I need to perform some action in the main form when the second form been unloaded. This is maybe one of the method of doing for relate to above topic, maybe for the code as

If frmFind.cmdReturn_click then
'perform action
End If

or does this relate to keypress? because I use toolbar to handle the find button and when been click it should load the frmFind and return with found record.

Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer

Private Sub Form_Load()
Me.KeyPreview = True
End Sub
 
Vincentan,

First question, are you using VB .NET, if that is the case every form oject should have a public function .Show
() and .ShowDialog().

And is it that you have 2 windows one which shows all your records and then by clicking "Find" you are launching "Find" window, right?? The easiest way to do this would be ( I am assuming that you have a common ancestor form for all your child forms )

1. Create a function or event on the ancestor form something like
Public Overridable Function findRecords(ByRef oFoundRow As DataRow) As Integer

End Function

2. Add code on Toolbar click to trigger the child windows findRecords function. Follow the thread below to see how we can trigger a function on child window from an MDI form thread796-507491

3. In your child window override the ancestor function
Public Overrides Function findRecords(ByRef oFoundRow As DataRow) As Integer

'Implement the code here to open the find window
Dim oFrmFindWindow as New frmFindWindow()
Dim oFoundRow As DataRow

'This should work
oFrmFindWindow.ShowDialog()

'Delcare an attribute "getFoundRow" in FrmFindWindow
'to return the found row user just searched
oFoundRow = oFrmFindWindow.getFoundRow()

'oFoundRow has the record we are looking for, so do whatever you want to do here.
End Function

Let me know if you have any problem

-Kris
 
Greats! Kris!
You are good in VB.net! I try to go for VB.Net but existing my project was VB6, is there any method of doing this? or the function only available in VB.Net?

[2thumbsup]
 
Vincentan,

You won't find any VB6 FAQ's in this forum. Try VB6 forum, may be you will find an answer to your question there. And in VB .NET, if you want to find a row with in a datatable, we can use Select, the syntax is as follows,

Dim oDataRow() As DataRow
Dim dtDateToSearch As DateTime = "01/01/2002 00:00:00"

oDataRow= oDataSet.Tables("MyTable").Select( _
"start_date = '" & dtDateToSearch & "'")

This will return me a datarow array of all that rows where start_date matches the date I have set.

-Kris
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top