Passing a value from one form to another

D

dave

Let me start out by saying I am a neophyte when it comes to Access. I
was "volunteered" for this project, so I have to make do with the
situation.

I am using A2003 on a pc; the application is for data entry of a
survey and the db contains one table with eight (8) forms (each being
a section of the survey.

On the first form is the survey ID; this is the value I need to pass
from one form to the next. I navigate to each form via a control
button, which I have a macro to close the form you are leaving and
open the form you desire.

What I need to do is to pass the survey ID from the first form to the
form I am going to open up. I read something about using a global
variable, but I have no idea on how to get it to work.

Perhaps I am going about this the wrong way, but I am at a loss on how
to accomplish on how to display the survey ID on each form when I only
capture the data on the first form.

Thanks so much for your help.
Dave
 
G

Guest

Dave

You could have a global variable or just as easy on each form you can have a
text box that will contain the ID this can be hidden if it is not to be seen
vie the Visible property of the txtbox.

You obviously have the ID in the first form so when you want to open up the
next you can assign the ID from the first to the second form with this in the
on click event of your button

Forms!NewForm.txtID = Me.ID

or if the first form used a txtbox to hold the ID

Forms!NewForm.txtID = Me.txtID
 
D

dave

Dave

You could have a global variable or just as easy on each form you can have a
text box that will contain the ID this can be hidden if it is not to be seen
vie the Visible property of the txtbox.

You obviously have the ID in the first form so when you want to open up the
next you can assign the ID from the first to the second form with this in the
on click event of your button

Forms!NewForm.txtID = Me.ID

or if the first form used a txtbox to hold the ID

Forms!NewForm.txtID = Me.txtID










- Show quoted text -

Thanks for your response, but I am having trouble following your
suggestion.

On form 1, the user enters the SurveyID into a textbox with a label
name "SurveyID" and control source being "SurveyID"; this is on the
detail section of the form. On the same form in the form header
section, I have another textbox "SurveyID2" and the control source is
SurveyID.

I use a button "Section 2", which OnClick executes a macro to execute
a Close command and then Open frmSection2. It is this form that I want
the SurveyID from form 1 to populate the textbox "SurveyID2" on form
2.

How can I incorporate your solution into my scenario? Please explain,
if possible, step-by-step as I am very new to this.

Thanks again for your help.
Dave
 
M

missinglinq via AccessMonster.com

Since you only have 1 table, I assume the 8 forms are simply a matter of real
estate, which is to say screen room. What you really should do is use tabbed
pages on a single form. That way you won't be doing this same old huckabuck
everytime you need to accomplish something! Here's a supper quick little
tutorial I send people:

First thing to remember is that the Tabbed Pages are all part of a single
form; think of it as a really long form turned on its side. Because it is all
one form, all referrencing to any contol on it is done in the same manner as
if they were all on one single screen. Create a form in Design View. Goto the
toolbox and click on the Tabbed Control icon; it actually looks like several
manila file folders. Place it on your form and adjust the size to your liking.
If you need more than the two tabbed pages it initially gives you, click on
the tabbed control to select it. Goto Insert and click on Tabbed Control Page
and another tabbed page will be added. Do this as many times as neccessary.

This is the really important part: when you go to add a control to a tabbed
page, you must first click to select one of the pages, then add the control.
Otherwise, the control will be added to the form itself, and will show thru
on all tabbed pages!

Once you have the form's Control Source (your table or a query) set up, you
simple add controls as you normally would, heeding the above paragraph.

--
There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000

Message posted via AccessMonster.com
 
D

dave

Since you only have 1 table, I assume the 8 forms are simply a matter of real
estate, which is to say screen room. What you really should do is use tabbed
pages on a single form. That way you won't be doing this same old huckabuck
everytime you need to accomplish something! Here's a supper quick little
tutorial I send people:

First thing to remember is that the Tabbed Pages are all part of a single
form; think of it as a really long form turned on its side. Because it is all
one form, all referrencing to any contol on it is done in the same manner as
if they were all on one single screen. Create a form in Design View. Goto the
toolbox and click on the Tabbed Control icon; it actually looks like several
manila file folders. Place it on your form and adjust the size to your liking.
If you need more than the two tabbed pages it initially gives you, click on
the tabbed control to select it. Goto Insert and click on Tabbed Control Page
and another tabbed page will be added. Do this as many times as neccessary.

This is the really important part: when you go to add a control to a tabbed
page, you must first click to select one of the pages, then add the control.
Otherwise, the control will be added to the form itself, and will show thru
on all tabbed pages!

Once you have the form's Control Source (your table or a query) set up, you
simple add controls as you normally would, heeding the above paragraph.

--
There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000

Message posted via AccessMonster.comhttp://www.accessmonster.com/Uwe/Forums.aspx/access-forms/200706/1

Actually, this is what I first attempted; but, as I added additonal
tabs, Access gives me an error that I can't create any more controls
on this form...I have 179 data elements in the survey. So I had to
scrap this plan on create eight individual forms. The tab approach
worked great, but MS foiled this attempt. If you know how I can
circumvent this problem, I would appreciate it greatly.

Thanks again for your help and expertise.
Dave
 
G

Guest

Ok try this, (sorry if it is a bit simplistic)

in the forms properties go to events, click the "..." next to the On Close
event and choose code builder this will open up the OnClose sub for the form
then just type in

Forms!frmSection2.SurveyID = Me.SurveyID2

that will pass the value of SurveyID from the one forms control to another
forms control.
 
D

dave

Ok try this, (sorry if it is a bit simplistic)

in the forms properties go to events, click the "..." next to the On Close
event and choose code builder this will open up the OnClose sub for the form
then just type in

Forms!frmSection2.SurveyID = Me.SurveyID2

that will pass the value of SurveyID from the one forms control to another
forms control.










- Show quoted text -

Thanks again for your help.

On frmSection2, what should the control source be for the text box
"SurveyID2"? Currently, it has "SurveyID" (which, of course it can't
find since it is on form1 and this form is closed).


Thanks for your patience.
Dave
 
G

Guest

No problem. Have you set a data source for the form in frmSection2 and if so
can you tell me what it is? i.e. is is Select SurveyID ... etc etc from ....
Where SurveyID = 1
 
D

dave

No problem. Have you set a data source for the form in frmSection2 and if so
can you tell me what it is? i.e. is is Select SurveyID ... etc etc from ....
Where SurveyID = 1








- Show quoted text -

If I understand your question correctly, "SurveyID2" (which is a Text
Box) has a Data Control Source = SurveyID; I don't have any sql code
behind it (i.e., no Select...from....)

I hope this answered your question.

Thanks again.
Dave
 
G

Guest

Dave

You need to check if the form has a data source without it you probably
havent bound the controls unless you have set it in code.

Either: On the top left of the form in design mode click the square and look
at the forms Data properties and see if there is a select statement in
DataSource

Or: Click your text box and in the contolsource click the drop down and see
if there is a list of fields to choose from if there is nothing in the list
then the data source form the form is not set.

Let me know

Paul
 
D

dave

Dave

You need to check if the form has a data source without it you probably
havent bound the controls unless you have set it in code.

Either: On the top left of the form in design mode click the square and look
at the forms Data properties and see if there is a select statement in
DataSource

Or: Click your text box and in the contolsource click the drop down and see
if there is a list of fields to choose from if there is nothing in the list
then the data source form the form is not set.

Let me know

Paul








- Show quoted text -

Paul,

I have a record source property, but I don't see "Datasource"
property. The record source points to my table and yes, I do have a
list of variables to choose from.

Dave
 
G

Guest

Oops I meant recordsource!

Anyway in the recordsource you should be able to change the Select statement
by putting a WHERE clause in it similar to

SELECT ........... FROM Surveys WHERE SurveyID = '" & Me.SurveyID & "'"

So, say in frmSection1 you have obtained a record and it has a surveyID of
23 which you have bound to a text field named txtSurveyID in the On Close
event type in

Forms!frmSection2.txtSurveyID2 = Me.txtSurveyID

In the record source for frmSection2 you would have

SELECT SURVEYID FROM Surveys WHERE SurveyID = '" & Me.txtSurveyID2 & "'"

Hopefully that should get you there.
 
J

John W. Vinson

.I have 179 data elements in the survey. So I had to
scrap this plan on create eight individual forms. The tab approach
worked great, but MS foiled this attempt. If you know how I can
circumvent this problem, I would appreciate it greatly.

You've fallen into the VERY common "each question as a field" trap. That's
natural, tempting, AND WRONG.

Rather than one *field* per question, restructure your tables so that you have
one *record* per question.

Duane Hookum has an excellent example of how to set up survey data:

http://www.rogersaccesslibrary.com/Otherdownload.asp?SampleName='At Your Survey 2000'

You'll find this much easier to manage.

John W. Vinson [MVP]
 
D

dave

Oops I meant recordsource!

Anyway in the recordsource you should be able to change the Select statement
by putting a WHERE clause in it similar to

SELECT ........... FROM Surveys WHERE SurveyID = '" & Me.SurveyID & "'"

So, say in frmSection1 you have obtained a record and it has a surveyID of
23 which you have bound to a text field named txtSurveyID in the On Close
event type in

Forms!frmSection2.txtSurveyID2 = Me.txtSurveyID

In the record source for frmSection2 you would have

SELECT SURVEYID FROM Surveys WHERE SurveyID = '" & Me.txtSurveyID2 & "'"

Hopefully that should get you there.






- Show quoted text -

Ahh...success.

Thanks so much for your help!! You guys are great!

Dave
 

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