Carry ID to from one form to another

M

Malcolm Andersson

Hi all. First time posting on a newsgroup so I may be posting something that
has allready been answerd to.

I have this database I've been devolping for a client and I've hit a problem
I cannot seem to solve.
In the first form the user search for the right dog (animal hospital). And
when the user has found the right one and pushes the button to go to the
Journal form I want the journal-form to get the ID number for the correct
dog so when they starts to type in the entries in the journal it gets under
the correct place.
The name for the first form is: Frm-Patientkort and for the second it is
Frm-Journal and the combo-searhc you search after the dog is called:
Hundens_namn_komob

Thanks in advance
Malcolm
 
G

Guest

If Frm_Journal has been opened as a modal form, then one way to proceed is to
pass the id using the OpenArgs parameter on the DoCmd.OpenForm statement e.g.
DoCmd.OpenForm "Frm_Journal",,,,,,Cstr(Hundens_namn_komob.Value)

In Frm_Journal's Load eventHandler, you can access this parameter using the
OpenArgs variable.

e.g. variable (or Control) Name = Clng(OpenArgs)

This approach will also work on forms that have not been opened as modal.
In these circumstances, you can also code after the DoCmd.OpenForm statement
if you wish to place the value into a control on the form e.g.
DoCmd.OpenForm "Frm_Journal"
Forms!Frm_Journal!txtDogId = Me.Hundens_namn_komob

Hope This Helps
Gerald Stanley MCSD
 
G

Geof Wyght

Malcom,
Another way to do this is when you have a query in Frm-
Journal that depends on the id selected in Frm-
Patientkort. The query might be the record source for the
form or the row source for a list box. To do this:
1) Make an invisible text box in Frm-Patientkort. Call it
txtHundensID. Assuming Hundens_namn_kombo is in Frm-
Patientkort, then in the after update event of
Hundens_namn_kombo, do:
Me.txtHundensID.Value = Me.Hundens_namn_kombo.Column(0)
2) Make your record source or row source query to look
like this:
Select HundensID, ... From xxx Where HundensID = [Forms]!
[Frm-Patientkort]![txtHundenID]

As long as Frm-Patientkort is still open, the query willl
pick up the correct records.
Hope that helps!
Geof Wyght
 

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