populating ID # into a subdocument

P

Paula5921

I am very new to Access and have been teaching myself as I go alsong, but I
am stuck now! I am using Access 2007.

I have a main form and 4 subforms, all for data entry. I call them
sub-forms, but they are not actually "dragged into" the main form. Don't know
if that's the problem or not!

On the main form, I used a 4 buttons, each with an "open form" command to
open each subform in its own window. Here's the problem - I want each subform
to open with the ID number that is in the currently open main form. Example,
if I have the main form populated with info from record #1(ID field), I want
the subform to open with the same ID field, #1.

How do I do that? I have tried several things, but nothing works. It's
beyond "teaching myself" now!

Could someone please help me?
 
D

Damon Heron

On the click event of your buttons, add this code:

Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "Name of the form you want opened" 'in quotes
stLinkCriteria = "[YourmatchingID]=" & Me![YourMatchingID]
DoCmd.OpenForm stDocName, , , stLinkCriteria

that's all, folks!

Damon
 
P

Paula5921

Thanks for the help, but I keep getting syntax errors. I am probably doing
something wrong. Could you please break down the steps for me. I have never
used code before and have no idea how to fix the syntax errors. The name of
my subform is fundraisers.

Thanks,
 
J

John W. Vinson

I am very new to Access and have been teaching myself as I go alsong, but I
am stuck now! I am using Access 2007.

I have a main form and 4 subforms, all for data entry. I call them
sub-forms, but they are not actually "dragged into" the main form. Don't know
if that's the problem or not!

Yes, it is.

If you use a Subform Control, you get a "Master Link Field" and "Child Link
Field" which AUTOMATICALLY, with no code and no effort, populate the linking
fields.

If you choose to use separate forms then you must do all the work yourself in
code. It's not all *that* hard if you know the tricks, but it's certainly
extra work... and except in extraordinary circumstances it's unnecessary work!

Have you considered using Subforms, or do you have some explicit reason to do
it the hard way?
 
T

Treasa

John,

I am following this thread and have a similar problem. I have a main form
and subform. The subform is linked, parent/child, using field CourseID -
this works fine as far as populating the form with date related to the parent
(CourseID).

My problem:
1) The table the subform is based on has fields in which the user must
enter data, i.e., attendance of students (students already have records).
The linked field, CourseID, is not being populated in this table.

2) In addition, I need to populate another field in the subform with the ID
number of the main form so I can link the data in the subform to the data in
the main form for reporting purposes.

I hope this information is clear enough for you to understand. I am under
the gun to produce this db ASAP. Any suggestions??
 

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

Similar Threads


Top