Results 1 to 5 of 5
  1. #1
    RonL is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2009
    Location
    NJ
    Posts
    114

    Textbox ControlSource Question

    Hello. This is really basic, but I gotta face up that I don't understand it. Googling gives a ton of stuff, but most of it at a higher level than this must be.

    I have a textbox in the header section of a form. I want it to display a value based on this query:

    Code:
    SELECT CamerasTotal
    FROM tblShoots
    WHERE (([tblShoots]![ShootsID]=[frmShotList]![ShootsFK]));
    tblShoots is 1 to many related to tblShotList and the recordsource for frmShotList is a query based on tblShotList (and the problem is the same if I substitute that query for frmShotList in the where clause.)



    When I test this query, it asks me for the frmShotList!ShootsFK, even though frmShotList is open and a particular record, which contains a value for ShootsFK, is current. So it's no wonder the textbox shows the #Name error when I make that query its controlsource. What am I missing? Note that I don't really care about *binding* the textbox, I just want it to display a value based on other data in the form. Should I be using a different control? Is this some sort of scope issue?

    Thanks for any help. -Ron

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    Well, that isn't the correct syntax:

    Forms Refer to Form and Subform properties and controls

    Further, you can't use SQL as the control source of a textbox. You can use DLookup:

    DLookup Usage Samples

    Or you could have that SQL as the row source of a combo.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    RonL is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2009
    Location
    NJ
    Posts
    114
    Thank you, thank you! I'd seen those links before, but bookmarking them now. And I gotta repeat 100 times: a combo box value reference must include the .column(n) property!

    -Ron

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    Happy to help! To clarify, a combo reference needs the column specified if you want a column other than the bound column.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    RonL is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2009
    Location
    NJ
    Posts
    114
    Quote Originally Posted by pbaldy View Post
    Happy to help! To clarify, a combo reference needs the column specified if you want a column other than the bound column.
    Which is my case.

    New issue: The following

    Code:
    ?nz(DLookUp("CamerasTotal","tblShoots","tblShoots!ShootName = '" & [Forms]![frmShotList]![cboShootName].column(1) & "'"),"No cboShootName")
    works in the immediate window (when form is in form view), giving the expected result whether cboShootName is populated or not. It also works as the control source for the textbox after pasting it in in design view and going to form view, whether the cbo is populated or not. But leaving it as the control source and closing the form causes Access to crash when next opening the form in form view. This probably has something to do with the fact that the cboShootName is null on form load (despite my using the Nz function), and I'll deal with that appropriately. But the problem sure has cost me a lot of time to figure out. To facilitate development, more precise insight into what's happening would be appreciated. Is there some sort of OnLoad catch-all error handler?

    Thx, Ron

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Dynamic Text Box ControlSource from multiple tables
    By cjtezak in forum Programming
    Replies: 2
    Last Post: 06-20-2012, 10:07 AM
  2. Replies: 8
    Last Post: 06-02-2012, 11:26 AM
  3. New to VBA - Textbox/ List question
    By dreamnauta in forum Programming
    Replies: 6
    Last Post: 12-21-2011, 01:41 PM
  4. Replies: 2
    Last Post: 10-27-2011, 10:28 AM
  5. Subform ControlSource Popup issue
    By GraemeG in forum Forms
    Replies: 10
    Last Post: 04-07-2011, 11:52 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums