Passing form's Data to different forms in a project (1 Viewer)

Engr. Matthew

New member
Local time
Today, 03:11
Joined
Feb 27, 2021
Messages
9
I have a particular form that contains a unique number, let say card number I want to use as a search parameter on a form.
I have Textbox for example txtCardno. and a command button to retrieve the patient information. On each form there is a command button that opens the same Form, which use listbox to display patient records.
I placed this code on a double click (Forms![formname]!txtPhone = Me.lstboxname.Column(4)) I use this line of code to retrive card noumber when double click on a selected patinet record on the form. the form closes and the card number of the patient displayed on the txtCardno on the main form, clicking search button retrieve the patient's record. It works fine. however, this solution required me to have different copy of the form to each of the forms I want to use the form which is much. what really want is to have only one sigle form to be open in each form and let the form post data using generic code that use varants object to accomplish the task

Now, how can I modify the duoble click code of the form to a generic code to retrive the name of the form opened from and pass the data to the form control without have many copies of the form for each form I want use the form.
 
With VBA, options for passing data between forms are OpenArgs, global variable, TempVar (macro can also refer to TempVar), one form refers to control on another form (as you already do).
 
Last edited:
I don't think I have grasped the essence of your question... However I have a class module which might meet your requirements as I understand them...

Have a look at this webpage on my nifty access website here:-

 
On each form there is a command button that opens the same Form, which use listbox to display patient records.
Let's say that button's click event code looks like this:
DoCmd.OpenForm "FormName"

You might have other stuff there, but it seems you want that form to know who called it. One strategy is to pass the name of the form through the OpenArgs parameter of DoCmd.OpenForm like this.
DoCmd.OpenForm "FormName", , , , , , Me.Name

If you do that, your listbox form will store the name of the form that called it by accessing its OpenArgs property. That way, you'll be able to do this for the double click event of your listbox:
Forms(Me.OpenArgs)!txtPhone = Me.lstboxname.Column(4)

That is the generic code you're probably looking for.

What you have to know is that Forms have an OpenArgs property that you can set through DoCmd.OpenForm's OpenArgs parameter.
 
Last edited:
I attached this code
Private Sub lstPatient_DblClick(Cancel As Integer)
Forms(Me.OpenArgs)!txtPhone = Me.lstPatient.Column(4)
End Sub
this code generated error mismatch
 

Attachments

The OpenForms method has a WHERE argument. That is where you use the FK value. Then you can use the OpenArgs to pass in the name of the calling form. I ALWAYS pass in the name of the calling form because I hide the calling form when I open a second form That way the called form knows which form it needs to return to in the case where the second form could be called from multiple other forms.

So, using the arguments of the OpenForms method correctly, not only do you get to control which record gets opened but you also get to tell the called form which other form called it. Pay attention when you see intellisense and if you don't understand what you are seeing, take the time to look at the help entry. Otherwise, you never learn anything.
 

Users who are viewing this thread

Back
Top Bottom