Passing data from one form to another

andreas_udby

Registered User.
Local time
Today, 17:03
Joined
May 7, 2001
Messages
76
Okay, I know this is fairly simple, but I'm suffering from a case of "coder's block" in how to make this work.

I have a parent form, frmPatient, with a subform on it, called frmSubVendor. The main form gathers information about a patient and the subform shows the contact info for the vendor they have been referred to by the nurse. The parent/child forms are linked by a Long Integer field called vendorID by means of a non-visible text box (txtVendorID) on the parent form. When I manually change the vendorID value in that text box, the subform updates to show the vendor's info.

There is a button on frmPatient that says "Select Vendor". When clicked, this button opens up a modal form, frmSelectVendor, which contains a list box (lstVendor) showing a list of available vendors.

The user filters the list box by means of four dancing combos and then selects the vendor they need by clicking on it. At this point, the vendorID they selected should appear in txtVendorID on the main form, thanks to the following:
Code:
Private Sub lstVendor_Click()
    Forms!frmVetInput!txtVendorID.Value = Me!lstVendor.Value
End Sub
They then click a button (cmdSelectClose) that closes the modal form and returns them to the main form. In theory, the subform should be showing the vendor's info, since the value in txtVendorID has changed and there is an AfterUpdate() routine for the text box which performs a .Requery on the subform.

However, I can't seem to find a reliable way to pass the vendorID from the list box on the modal form to the text box on the main form (which is what the subform links to in order to pull the correct vendor record), and then make the subform update itself to show the selected vendor's information. I'm sure there is a very simple way to do this, but I'm just drawing a complete blank as to how to go about it. Any help is appreciated!

Thanks,
Andreas
 
Last edited:
I think you will find that setting a controls value through VBA does not trigger the AfterUpdate event. You could try manually refreshing/requerying the subform after sending the Vendor id to the main form;

forms!frmPatient.frmSubVendor.requery
 
Oh, really? Shoot. That's good to know! I suppose that would apply to the Change() event as well?

I had indeed tried to requery the subform, first by including it in the modal forms's command button's Click() routine and then by giving the main form the same line in a GotFocus event, but neither seems to prompt it to change. I don't want to add a button the nurses have to push to requery it, as they need to do as little clicking as possible, given their workload.

Thanks,
Andreas
 
another method that may work, would be to requery the main form then use the recordset.Find method to set the main form back to the selected Vendor.
 

Users who are viewing this thread

Back
Top Bottom