Passing form parameter to another form?

S

SF

Hi,

I have a general contact search form that will easy to locate name, location
, telephone number from contact table. If the information is found, user can
click add bottun to add information for people who participate in social
event. I want to use the search form with another form called Monthly
Meeting, I can cal the search for from a button, no problem.

Now I need to decide what table to update based upon which form called to
search for to open. In this case, how can I pass the form name and ID of the
record to the search form so that the search know which table to update? Is
there a way to use ByVal or ByRef to detact which form?

SF
 
A

Albert D. Kallal

There usually two ways.

idea #1, open the form to the SAME record.

so, if you have a grid, or continues form of records that are the result of
a search, then behind a button to "open" that one form to the SAME ONE
record, you simple go:


dim strWhere as string

strWhere = "id = " & me!id
docmd.OpenForm "frmEditDetails",,,strWhere

The above will open the form to the SAME current record you are on. So, in
effect you don't have to pass the current id you are on, but simply open the
2nd form to the same record you are currently on (then, that form can access
the id, or any other field in the table for the same record).

# idea.

You can use the "openArgs" command to pass the id to the form.
eg:


docmd.OpenForm "frmEditDetails"

docmd.OpenForm "frmEditDtails",,,,,,me!id

Then, in the form "frmEditDetails" open event, you can go:

msgbox "pass id = " & me.OpenArgs

So you can use the "args" parameter to pass a value, but often it is better
to simply use the "where" clause as per my first example since then you
don't have to write code to "move"/"setup" the form to the one record based
on that id passed.....

Which approach you use likely depends on if the form you are opening needs
to be restricted to the record with the same id as the current form you are
on...

Also, don't forget if you allow the 1st form to edit the same record, then
you need to force the record to be written to disk BEFORE you launch the 2nd
form to the same record (else you get a nasty error about how some other use
edited the same record...but in fact it's the same user but 2 forms trying
to edit the same record).

You would force the disk write like:

dim strWhere as string

if me.dirty = true then
me.Dirty = false 'disk write record
end if

strWhere = "id = " & me!id
docmd.OpenForm "frmEditDetails",,,strWhere
 

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