Passing a fields data into various forms

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am using Microsoft Access 2002, and have various forms that incorporate a
search button; each of these forms will open the same search form
(frmDonorLookup).

The frmDonorLookup form has fields that the user will type parameters into,
the form also has a search button, and a listbox. When the user types in the
search parameters and clicks the search button, the listbox (which is based
on a query using the fields as parameters) will requery with the appropriate
search results.

What I would like to do is have the user click a select button (btnSelect)
to pass the selected listbox value into the original form that opened the
search box, regardless of which of the various forms has opened the listbox.
I have been able to determine the original form by using Screen.ActiveForm,
but I can't seem to pass the value from the frmSearchForm back into the
original form.

Any assistance would be appreciated.

Thanks,

Leo Saumure
 
The Tick said:
I am using Microsoft Access 2002, and have various forms that incorporate a
search button; each of these forms will open the same search form
(frmDonorLookup).

The frmDonorLookup form has fields that the user will type parameters into,
the form also has a search button, and a listbox. When the user types in the
search parameters and clicks the search button, the listbox (which is based
on a query using the fields as parameters) will requery with the appropriate
search results.

What I would like to do is have the user click a select button (btnSelect)
to pass the selected listbox value into the original form that opened the
search box, regardless of which of the various forms has opened the listbox.
I have been able to determine the original form by using Screen.ActiveForm,
but I can't seem to pass the value from the frmSearchForm back into the
original form.

Any assistance would be appreciated.

Thanks,

Leo Saumure

The smart way of doing this is as follows:

1. When you open your search form, do so with WindowMode:=acDialog. This
will cause the code to stop at the OpenForm method, where it will wait for
the search form to be closed or (crucially) hidden.
2. When the user clicks the Select button, hide the search form i.e. set
it's visible property to False.
3. The code in the original form will now start running again but,
because the search form is still open, albeit hidden, you can reference the
search form and obtain the value from the list box. Then, when you've got
the value, you can close the search form using DoCmd.Close.
 
You suggestion worked great. I added an OpenArgs along with opening the form
in acdialog. By using the OpenArgs I was able to pass the form name into the
frmDonorLookup form. Adding this code to the various forms ensures that
after searching, the focus will revert back to the proper form.

The code for the form(s) that opens the frmDonorLookup looks like this:
-----------------------------------
Private Sub btnSearch_Click()

Dim stDocName As String
Dim stLinkCriteria As String
Dim frmParent as Form

Set frmParent = Screen.ActiveForm

DoCmd.OpenForm stDocName, , , stLinkCriteria, , acDialog, frmParent.Name

'When code resumes, do something

End Sub

-----------------------------------

The code for the search form looks like this:

-----------------------------------
Private Sub btnSelect_Click()

Dim frmOrigForm as Form

Set frmOrigForm = Forms(OpenArgs)

'Passes the value from the search form to the original form
frmOrigForm!txtSearchString = Forms!frmDonorLookup!txtSearchString

DoCmd.Close

End Sub
 
Back
Top