Pull information from subform

A

Alex

Hi,

I have a form (Registrants) with a subform (Test attempt). On the subform,
there are fields: Test_ID, Registration ID. There is also a command button
which opens another form called QA.

The form QA has fields: question, answer, registration id, test id. It is
based on a query.

I need the form QA to pull the registration id and test id from the subform
Test Attempt. However, I don't want the form to requery based upon the test
id and registration id since then it would be empty. I want it to fill these
fields in instead. Make sense?

Is there a way to do this?

Thanks,
Alex

Thanks,
Alex
 
B

Barry Gilbert

Check the online help for the form's OpenArgs property. It allows you
to pass values into a form when calling the Docmd.OpenForm method. You
could pass the values in as a comma separated string like
questionValue,answerValue,regidValue,testidValue

In the QA form, you would take the OpenArgs property and parse the
values from this string and then do what you want with them.

This is the cleanest approach because it allows the forms to be
decoupled. However, a simpler, but more coupled approach is to have the
QA fdorm directly reference the TestAttempt form's values using
Forms!TestAttempt.<ValueName> or Forms!TestAttempt.<ControlName>.

HTH,
Barry
 
A

Alex

HI Barry,

Thanks for the help. Can you be a bit more explicit though? I am a newbie
to coding so really don't know where to put the code, or how.

Thanks,
Alex.
 
A

Alex

Hi Barry,

I was able to directly reference the form field in the control source box:
=Forms!frm_Registrants!frm_Test.Form!registration_id.

The form now LOOKS like it is working.

But when I go to the Answers table (which this form is supposed to update),
the registration ID field is empty.

Any ideas as to why?

Thanks,
Alex.
 
B

Barry Gilbert

You don't want to put it in the ControlSource property. The
controlSource should refer to the field in the underlying table. Try
putting the reference in the text box's Default Value property.
 
A

Alex

Hi Barry,

I set the reference in the default value property. It only works if I press
CTRL-ALT-SPACEBAR. Is there a way to have it fill in without that key
combination?

Thanks,
Alex.
 
B

Barry Gilbert

Change of plans:
In the QA form's property sheet, start a new procedure in the On Open
event. Insert the following code:

Private Sub Form_Open(Cancel As Integer)
' Substitute whatever your control is called.
Me.txtRegId=Forms!frm_Registrants!frm_Test.Form!registration_id

End Sub

Do the same thing for any other controls you need to populate.
 
A

Alex

Hi Barry,

I tried your code and it says "You can't assign a value to this object".

the code I typed in the OnOpen event was:
Private Sub Form_Open(Cancel As Integer)
Me.registration_id =
Forms!frm_Registrants!frm_Test_Attempt.Form!registration_id
End Sub

Any ideas?

I really appreciate your ongoing support in this.

alex.
 
B

Barry Gilbert

Does Me.registration_id refer to a control or a field? Also, is the
query that the QA form is bound to updateable? You can test this by
opening the query directly and trying to insert/modify records.
 
A

Alex

Hi Barry,

Me.Registration_id is a text box with its control source as registration_id
in the underlying query.

The query appears to be updateable but that could be where some of the
problem lies?

The query is taking all questions (pre-filled fields) and joining with the
Answers table which are empty fields....so the form QA shows all questions
for a particular test and leaves blank answer fields for the student to fill
in.

If I actually type in the registration id and the test id, then the Answers
table updates accordingly. So, I should be able to code this, right?

Maybe this is a bigger problem though?

Alex.
 
A

Alex

I have done some testing...and yes, I have a bigger problem. If a test has
been pulled before for a student and QA form filled in, then the next time
that particular test is queried, the QA form shows the previous student's
answers.

Oh God....I really don't know where to go from here.

Do you have any suggestions?

Alex
 

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