Control source for subforms

  • Thread starter Thread starter kublakahn
  • Start date Start date
K

kublakahn

Guest
I have a database with 2 tables, in each table is a field (integer) that contains a number. The two tables are related one to many. I have made a form and a subform. The main form takes the number value from "table A" and performs a calculation (control source).
When I try to take the number value from "table B" and perform a calculation in the control source and display it on the subform (default view = datasheet), I get "#Error". Now if I just put "[field]" into the control source it displays the number, but if I preceed this with "=" I get the "#Error". I can't even increase the value by 1 (=[field] + 1).
I have also tried making a query and using that for the control source and that didn't work (I'm not really sure if it should, I'm just trying everything I can think of).

Can someone please help, thanks.
 
kublakahn,

I don't understand your question. Are the forms bound? Is the parent/child relation set? Are you using code?

Perhaps some else is quicker on the uptake but for me, there is not enough information.
 
Sorrellls,
Sorry for not providing more information, I am new to the database game. I'm not sure how to tell the information you want. I thought you bound individual controls (not entire forms).
The relation is one (table A) to many (table B), I don't know how to specify parent / child. I could send you the database if you wanted me to, it's only 69kb zipped up. Please let me know and thank you for your response.

Kubla
 
Kubla,

What version of Access are you running. In the Access97 help file index you can look for the topic 'subform' the following sub-selection is s good place to start reading up.

How Microsoft Access links main forms and subforms

The subform construct (or object) is a great way to display the one to many relationship, the subform being the many.

Take a look there and let me know if this helps. I don't have the time to look at the code until we are pretty well talking from the same side of the page. :)

Both the form and it's subform must be bound to create the parent/child relationship and Access forces this relationship in design mode if you drag and drop the subform on top of the parent form.

Let me know what you come up with.
PS: If you scroll down in the reply page, you will find a textbox where you can attach a text or jpeg file.
 
Sorrells,
I am using Access2000. I did find an explanation in the help file and I believe that the forms are bound (judging from the help file).

I am also attaching both a 97 version and 2000 version of the database (someone else requested).

Thanks again for your patience.

Kubla
 

Attachments

Kubla,

Your forms are unbound. No they are bound but Access is not recognizing it. There is something funny as when I opened the dB I got an Access error of 'unrecognizable format" but it let me open it.

When I deleted the subform from the main form then dragged it on top of the main form again, Access accepted it.

You have in the tracklength control and = sign as you had noted, but this is a specific field in the TRACKS table. It requires no annotation, just select the field from the dropdown list for Control Source.

I noticed that both the Name & ControlSource are named the same " TrackLength". It is good programming practice to never, never let them be the same name. I use prefixes to show the type of control as this is most useful in programming. I changed the name to txtTrackLength. Same with TrackTitle and TrackNumber.

Back to paragraph one, it also is good programming practice at times to compile all code in the program. Take any form and place it in design mode, find an event with code and open the code. Then on the menu select Debug/Compile and Save all Modules.

Take a look at the revised dB, make your cosmetic adjustments and I think you will do just fine.
 

Attachments

Since it's a subform you need to make some additions to the syntax. To pull the figure from the field in the subform type:

Forms!MainForm!SubForm!FieldName
 
Sorrells,
This worked, thank you very much. I think the problem was the naming of the control. Again, thank you for your time and patience.

Kubla
 

Users who are viewing this thread

Back
Top Bottom