Open form from a form

G

GRIFFO

I have a form called "representative_search" on which users search for a
represntative of a customer. Ie: One to many relationship from customer to
rep. I have the customer name and can/may have the customer id on the search
form as well, and want to add a command button that when clicked closes the
current search form and opens my customer form at the appropriate customer.
I am sure you clever guys and glas have got this functionallity all over your
Access databases.

I assume there is a way in which I can open that form so that it is filtered
by the customer_id, however is there a way at which I can open the new
customer form, at the apporpiate customer, without filtering? The reason
being is that the user would then need to exit the customer form and re-open
the form so that it was not filtered to view other customers data. Maybe
include a button to change the record source to unfiltered?

I am also concerned that any close command I have on a form will close it
and not execute the open the next form command line. Or owuld you open a
form first and then close the other form somehow by naming it specifically.

Any suggestions (generic code would be nice too! :) in regards to design or
actual functionality would be appreciated.

Here cheers to this wonderful forum.
 
D

Dan Artuso

Hi,
You can do this by using the OpenArgs argument of the OpenForm method.
When the form opens, you check for the OpenAtgs string (customer_id in our case)
and then display this record. So in the Close event of your search form...

DoCmd.OpenForm "NameOfForm",,,"customer_id = " & Me.txtcustomer_id
DoCmd.Close acForm, Me.Name

Then in the Open event of your other form...

Dim rs As DAO.Recordset

Set rs = Me.RecordsetClone
If Me.OpenArgs <> "" Then
rs.FindFirst "customer_id = " & CLng(Me.OpenArgs)
If Not rs.NoMatch Then
Me.Bookmark = rs.Bookmark
Else
MsgBox "Sorry, no match"
End If
End If

Set rs = Nothing

I'm not sure if you have to convert the OpenArgs string to a long or not!
**The above code is untested**
 
D

Dan Artuso

Sorry, ignore that other post!!
I used the WhereCondition instead of OpenArgs!!

Here is the correct statement:
DoCmd.OpenForm "NameOfForm",,,,,,Me.customer_id

This assumes you have customer_id in the form's recordset
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top