Results 1 to 3 of 3
  1. #1
    mnsemple83 is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Jul 2011
    Posts
    40

    Using concatenated strings in control source for report

    I wrote some code in VBA that takes fields from a query and concatenates their values to create one string that will be used in a text box control for a report. If a field is empty, it is not to be included in the report.

    The code was written in the OnCurrent event of the report. I declared a String variable, set it to include the concatenated value, and then set the control source to equal the string variable.



    When I view the report in print preview, it does not include the information. The code I had written is similar to this:

    Dim strSource As String

    strSource = IIf(IsNull([field1]), "", [field1] & ", ") & _
    IIf(IsNull([field2]), "", [field2] & ", ") & _
    IIf(IsNull([field3]), "", [field3] & ", ") & _
    IIf(IsNull([field4]), "", [field4] & ", ") & _
    IIf(IsNull([field5]), "", [field5] & ", ") & _
    IIf(IsNull([field6]), "", [field6] & ", ") & _
    IIf(IsNull([field7]), "", [field7] & ", ") & _
    IIf(IsNull([field8]), "", [field8])

    Me.TextBox.ControlSource = strSource

    Where did I make my error?

  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,521
    For starters, I'd use the format event of whatever section the text box is in. Secondly, I think you want to set the Value property, not the ControlSource property. Why not just set the control source in design view and not bother with code? There's nothing dynamic in what you're doing.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    mnsemple83 is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Jul 2011
    Posts
    40
    I changed my code so that the value is recorded in the Value property instead of the ControlSource property and pasted the code in the On Format property of the Detail section. When I go to view it in Print Preview mode, I get an error message stating "A custom macro in this report has failed to run, and is preventing the report from rendering." Everything is being done in design view.

    I was wondering if there was a way inside the query to not include any null fields in the result so when it is being used by the report, they are not included and no blank spaces are present.

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

Similar Threads

  1. Charts within subform in a control source
    By GraemeG in forum Forms
    Replies: 0
    Last Post: 06-03-2011, 04:38 AM
  2. control source
    By nashr1928 in forum Forms
    Replies: 5
    Last Post: 03-12-2011, 09:31 PM
  3. Control Source
    By sarah54 in forum Access
    Replies: 1
    Last Post: 03-07-2011, 09:00 PM
  4. Control Source for Text Box (#error)
    By km8415 in forum Forms
    Replies: 3
    Last Post: 06-27-2010, 10:45 AM
  5. Replies: 2
    Last Post: 07-30-2009, 08:02 AM

Tags for this Thread

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