Basically I just need the id of the record on the first form so I can stick it in the foreign key column of the record on the second form. How do I pass this information along? Please ask for clarification in comments if this is not enough information.
views:
30answers:
2
+2
Q:
How would I have a MS Access form come up with certain fields pre-populated from the previous form?
+2
A:
If the first form calls the second form, then you can create a function that has as a parameter the object you want to pass in. Then after form creation, call the function.
Below is some psuedo code to demonstrate the calling of the new form and sending of the needed data.
public sub OnClick() {
Form2 frm = new Form2
frm.Initialize( recordId )
frm.Show
}
JDMX
2010-02-25 17:18:05
Well said and good example code
Bentley Davis
2010-02-25 17:22:14
This is not VBA. Why assume something other than VBA with an ms-access tag?
Remou
2010-02-25 18:11:41
The method in this non-VBA code is suggestive, though. You could design your called form to have a custom property that you could assign. Unfortunately, you could only do so if you don't open it with the acDialog argument, so if you need to pause code while the called form is open, this approach wouldn't work.
David-W-Fenton
2010-02-25 19:11:45
This example came out of an Excel project I did in 2000. I remember copying it into Access for another project but do not have that file. Although it may not be what the asker is looking for, it is a valid response.
JDMX
2010-02-25 19:18:30
It may be valid somewhere, but not in VBA.
Remou
2010-02-25 19:40:22
This is basically what I ended up doing. Slightly different code but the idea is the same.
Daniel Straight
2010-03-01 16:28:03
+2
A:
The OpenForm method of DoCmd has both a where argument and an OpenArgs argument. OpenArgs is likely to suit.
DoCmd.OpenForm "FormName",,,,,, Me.ID
It is also possible to get the information from an open form.
Remou
2010-02-25 18:17:47