Results 1 to 7 of 7
  1. #1
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 7 64bit Access 2003
    Join Date
    Feb 2011
    Posts
    2,097

    Text Box ControlSource "apparently" invalid

    In the footing of a continuous form, I have a text box whose ControlSource is:



    Code:
    iif(intNewCatID = 0,"",DLookup("[CategoryName]","tblCategories","CatID = " & intNewCatID))
    The form displays with an apparent error:
    Click image for larger version. 

Name:	CSBox.jpg 
Views:	9 
Size:	6.9 KB 
ID:	22930

    To view the situation in debug mode, I inserted the code in the OnOpen event with the appropriate stop:
    Click image for larger version. 

Name:	CSBoxCS.jpg 
Views:	9 
Size:	29.3 KB 
ID:	22931

    As you can see in the above screenshot, the IIF statement returned the appropriate text string given the current value of intNewCatID.

    What am I missing when the IFF is used as the ControlSource property of the textbox?

  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,652
    An = at the beginning?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 7 64bit Access 2003
    Join Date
    Feb 2011
    Posts
    2,097
    Fails even when I add brackets:
    Code:
    IIf([intNewCatID] = 0, "", DLookup("[CategoryName]", "tblCategories", "[CatID] = " & [intNewCatID]))

  4. #4
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 7 64bit Access 2003
    Join Date
    Feb 2011
    Posts
    2,097
    "=" already there:

    Click image for larger version. 

Name:	CSWithEq.jpg 
Views:	8 
Size:	38.9 KB 
ID:	22933

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    If intNewCatID is a VBA variable, you can't refer to it from the control source. You'd either have to use a public function that returned the value of the variable or maybe a TempVar.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 7 64bit Access 2003
    Join Date
    Feb 2011
    Posts
    2,097
    That's kind of subtle, to say the least. Anyway, I now see how to fix the issue.
    Thanks,
    Bill

  7. #7
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    No problem. We've never been able to access VBA variables outside VBA.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 1
    Last Post: 09-07-2015, 08:00 AM
  2. Replies: 10
    Last Post: 09-08-2014, 06:07 PM
  3. Replies: 5
    Last Post: 06-26-2013, 02:29 PM
  4. Export "Query or Report" to a "Delimited Text File"
    By hawzmolly in forum Import/Export Data
    Replies: 3
    Last Post: 08-31-2012, 08:00 AM
  5. Replies: 13
    Last Post: 12-05-2011, 05:10 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