Page 1 of 3 123 LastLast
Results 1 to 15 of 34
  1. #1
    DHavokD is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jun 2009
    Posts
    31

    Question Display Table Elements as a Paragraph with Numbering?

    So I have a query that takes 4 differents fields of an entry and combines them into a block of text (with some nice formatting of course).

    Now for the report a bunch of these blocks of texts need to be combined and numbered. So if the table was:

    Bob House Cat
    Jim Apartment Dog
    Betty House Hamster

    The paragraph would be:
    1. Bob: House; Cat; 2. Jim: Apartment; Dog; 3. Betty: House, Hamster;



    So the two things I cannot figure out:
    1. Numbering them as the query outputs them.
    2. Make it so its a run on paragraph.

    So right now I have:
    Bob: House; Cat;
    Jim: Apartment; Dog;
    Betty: House; Hamster;

    Note: If it matters, the data comes from a query and this is a sub-report of a main report. And this data is completely random made up stuff for the purpose of example.

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Maybe this link will be helpful.

  3. #3
    DHavokD is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jun 2009
    Posts
    31
    This appears to do what I have already done. I already wrote the SQL into the query to combine the four fields of each record. The problem is numbering the records as they pop out on the report, and not having them line separated.

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    If you are using a UDF then you can number them in the function. Is your UDF putting in the vbCrLf?

  5. #5
    DHavokD is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jun 2009
    Posts
    31
    I dont have a CrLF anywhere, this is the code that defines the field in my query:

    Update: "::" & Consolidated.Title & ":: " & IIf((Consolidated.Description<>""),("DESCRIPTION: " & Consolidated.Description & "; "),"") & IIf((Consolidated.[Significant Events - Past]<>""),("SIG EVENTS PAST: " & Consolidated.[Significant Events - Past] & "; "),"") & IIf((Consolidated.[Significant Events - Future]<>""),("SIG EVENTS FUTURE: " & Consolidated.[Significant Events - Future] & "; "),"") & IIf((Consolidated.Description<>"") And (Consolidated.[Significant Events - Past]<>"") And (Consolidated.[Significant Events - Future]<>""),"","No Significant Events; ")

    Basically puts those four fields together. Would it be possible to add numbering at this point? Cause a query add new autonumbers?

  6. #6
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    You have a field named *Update*?? Are you aware that that is a reserved word? That is one heck-of-an IIF structure. I would still do it as a UDF just for readability and maintainability.

  7. #7
    DHavokD is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jun 2009
    Posts
    31
    Okay changed it from update... But still, how would I number the entries? Either at query level or as they are popped into the report...

    And dont you know terri-bad code = job security.

  8. #8
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    The code I pointed to is a UDF that does all of the work but it looks like your fields are all on one record, is that correct? The UDF I pointed to works when the fields are on different records.

  9. #9
    DHavokD is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jun 2009
    Posts
    31
    Yes, all the fields are in one record. I just need to figure out how to number the records, can you add autonumbering in a query?

  10. #10
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    I get the feeling you are not real comfortable with VBA code. It also looks like the numbering you want is with the fields concantenation on one record and not with numbering each record in the RecordSet. A UDF would accomplish this and I would be glad to assist you in creating the UDF.

  11. #11
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    In studying your nested IIF statements, they do not return a string in the form you described in your first post. There is added text to the string such as "SIG EVENTS FUTURE: ".

  12. #12
    DHavokD is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jun 2009
    Posts
    31
    Ya I later added that, just as a way for me to say what each block of text was. So I get as reference my original, it actually does this:

    ::Billy:: RESIDENCE: House; PET: Cat; (etc)

  13. #13
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    This should give you something to work with for your UDF.
    Warning <<< AIR CODE >>>
    Code:
    Function MyString(InDescription As String, _
                      InPast As String, _
                      InFuture As String) As String
       Dim MyCount As Integer
       MyCount = 0
       ' Receive up to 3 strings in the following form:
       ' Bob: House; Cat;
       ' Jim: Apartment; Dog;
       ' Betty: House; Hamster;
       ' Return them in one string in the following form:
       ' 1. Bob: House; Cat; 2. Jim: Apartment; Dog; 3. Betty: House, Hamster;
       ' In our case it is invoked in a query this way:
    '      YourField = MyString(Consolidated.Description, _
    '                           Consolidated.[Significant Events - Past], _
    '                           Consolidated.[Significant Events - Future])
       If Len(InDescription & "") > 0 Then
          MyString = "1. DESCRIPTION: " & InDescription
          MyCount = 1
       End If
       If Len(InPast & "") > 0 Then
          If Len(MyString & "") > 0 Then
             MyString = MyString & " 2. SIG EVENTS PAST: " & InPast
          Else
             MyString = "1. SIG EVENTS PAST: " & InPast
          End If
          MyCount = MyCount + 1
       End If
       If Len(InFuture & "") > 0 Then
          Select Case MyCount
             Case 0
                '-- Nothing so far
                MyString = "1. SIG EVENTS FUTURE: " & InFuture
             Case 1
                '-- Only one parameter so far
                MyString = MyString & " 2. SIG EVENTS FUTURE: " & InFuture
             Case 2
                '-- Got both prior parameters
                MyString = MyString & " 3. SIG EVENTS FUTURE: " & InFuture
          End Select
       Else
          If MyCount = 0 Then
             '-- We need to return at least something
             MyString = "No Significant Events; "
          End If
       End If
    End Function

  14. #14
    DHavokD is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jun 2009
    Posts
    31
    Ah you are thinking of different counting than i meant.

    Lets say the four fields of each record are combined to make a "paragraph" of that record. Right now the query that does this turns my sample set of data into 25 "paragraphs". What I am trying to do is have the "paragraphs" themselves numbered:

    1. Paragraph1
    2. Paragraph2
    3. Paragraph3
    ...
    25. Paragraph5

    I am thinking the easiest way would be to have the query itself attach a number to each paragraph it outputs (some autonumbering possible in a query?).

    I am at home till Tuesday, which means on a mac and without my database or Access to mess around with. So if you got any suggestions by Tues would be awesome.

  15. #15
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Oh! Maybe what you are looking for is one of Stephan Lebans' routines.

Page 1 of 3 123 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Paragraph
    By supatsiri in forum Reports
    Replies: 0
    Last Post: 02-06-2009, 10:05 PM
  2. Replies: 3
    Last Post: 10-23-2008, 08:43 AM
  3. Table elements being replaced
    By HurrMark in forum Forms
    Replies: 0
    Last Post: 09-15-2008, 07:53 AM
  4. Numbering records
    By knightjp in forum Database Design
    Replies: 0
    Last Post: 08-17-2008, 07:07 AM
  5. Replies: 0
    Last Post: 04-19-2008, 09:08 PM

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