Maintaining UserID across multiple forms

H

Hadavidi

The db I am trying to work on is for a small clinical study. My knowledge of
using VBA is nil to non-existent. I am trying to learn as I go. So, pls bear
with me. As I see it there are multiple issues I am dealing with:

Let's say there is a demographic data entry form. Once the user enters the
demo info for a participant and saves this info, a prompt should pop up
asking if the user would like to enter medication info for this patient.

=> If the user chooses yes, then it should take them to the medication data
entry form. Assuming they enter this info and save it, it should prompt them
and ask if they would like to enter diagnosis info.

=> Across all these forms, how do I make sure that I have participant ID
from the demographics form.

=> Another issue is, for a given participant, there may be more than one
diagnosis or medication that they are on. On the form, I am planning to
display a list box from which the user can choose. Once the user chooses
either multiple medications or diagnosis, how do I do a multiple update.
Ahead of time, its hard to know how many medications or diagnoses a given
participant may have.

Any pointers or hints would be greatly appreciated especially with adding
the code behind the form.

Thx
Hadavidi
 
R

Randy Wayne

I will address one way to pass data from one form to another. There are many.

The easiest one for me to understand at the beginning of my VBA curve was to
keep the form that "held" the data I want to "pass" to other forms open, but
not visible. Here is how:

Say you have a form to log in, with a name field and a userID.

The Form is called frmLogIn
The text box for the name is called txtName
The textbox for the userId is called txtID.

After entering the name and userID, the user clicks a button to open a form
to enter Medical data.

The second form is called frmMedData.
This form also has a text box for name called txtName
It also has a text box for UserID called txtID


Add code to your "Save" (or "Add") button on the frmLogin.
(If you have a save button it would be after the code that looks like this:
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70)

Here is the code to add:

Me.Visible = False
DoCmd.OpenForm "frmMedData"
Forms!frmMedData.txtName.Value = Forms!frmLogIn.txtName.Value
Forms!frmMedData.txtID.Value = Forms!frmLogIn.txtID.Value

How this works is that it "hides" the first form (Me.Visible = False) but
leaves it open to use its values. From there you simply pass values from one
text box to another by specifying the textbox you want to fill being equal to
the text box that has the values you want. You can do this over and over as
long as the form is open.

When you are finished, don;t forget to close the hidden form. In this case
the following lione of code should be added at the end of the last step.

DoCmd.Close acForm, "frmLogIn"

Good luck and happy coding!
 

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