Results 1 to 5 of 5
  1. #1
    New Lounger
    Join Date
    Jul 2002
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Reference a Subform (Access XP SP1)

    I'm sure this will be very easy for someone here, but I'm not sure what syntax to use to reference a Text Box on a Subform:

    I have a Form called 'frm_CompilationRecord' containing a Subform 'frm_CompilationTrack'. On this Subform is a Text Box called 'txt Sum of B Rating by Count'--its Control Source is =[txt_Sum_of_B_Rating]/[txtCountTracks].

    I would like to add a Text Box named 'Grand Total' to the Main Form that copies the value of the Subform's Text Box. I learned a wee bit of VB, but I know Access is kinda different, so I'm not sure how this would be. I assume it would be something like this . . .

    txt.GrandTotal=[txt_Sum_of_B_Rating]/[txtCountTracks].

    . . . but I would really appreciate someone helping with the correct syntax, etc

    I presume this would go in the Control Source of 'txt.GrandTotal, or would this need to be done in the VB Code?

    Thanks heaps in advance.

    BTW, just while I'm posting, is there a way to get a Form or Text Box to AutoRefresh or AutoRequery at, perhaps, 5-second intervals?

    Thanks in advance for any help! <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

    Brian

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Reference a Subform (Access XP SP1)

    To refer to controls on a subform, use the syntax [SubFormName]![ControlName] where subFormName is the name of the subform control on the main form - this is not necessarily the same as the name of the subform in the database window. In the following example, I've assumed that the control name is the form name.

    Put the following in the ControlSource property of txtGrandTotal on the main form:

    =[frm_CompilationTrack]![txt Sum of B Rating by Count]

    In my experience, it shouldn't be necessarily to have a form refresh or requery itself at regular intervals. If the design is right, every change to the data by the user will trigger a refresh/requery. It's different for changes by other users in a multi-user environment, but it can be confusing to see values change suddenly.

    But if you really need it: forms have a Timer event and a Timer Interval property. Both are found on the Events tab of the Properties window. If the Timer interval is 0 (default), the Timer even't doesn't fire. The timer interval is in milliseconds, so a value of 5000 means that the Timer event will fire every 5 seconds. You can write code for the Timer event the same way you write code for other events.

  3. #3
    New Lounger
    Join Date
    Jul 2002
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Reference a Subform (Access XP SP1)

    Thanks heaps for your excellent reply. I thought this was going to work, but after I opened the Form, I just got a '#Name?' appearing in the Field. I've checked the names, and they're correct?????

    Any ideas what happened?

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Reference a Subform (Access XP SP1)

    Without seeing the database, it's hard to say what went wrong.

    I have attached a zipped Access 97 database with a main form and subform. The main form contains a text box txtSum that refers to a text box txtSum on the subform.
    You'll have to unzip it and convert it to XP. Perhaps looking at the way it's put together will help.

    Regards,
    Hans
    Attached Files Attached Files

  5. #5
    New Lounger
    Join Date
    Jul 2002
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Reference a Subform (Access XP SP1)

    Thanks for all your help. It turns out that the Syntax is different in XP. I used the Control Source (ellipses) button to invoke the Expression Builder (should have done that to begin with, but at least I've learned something . . . or remembered it--I don't know which!) and this is what the result was:

    =[Compilation Track].Form!txtSumOfBRatingByCount

    . . . and it WORKS! Wahoo!

    Thanks again for your kind help. It was greatly appreciated.

    Brian

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •