Page 1 of 4 1234 LastLast
Results 1 to 15 of 56
  1. #1
    deepaksharma is offline Competent Performer
    Windows 7 32bit Access 2016
    Join Date
    Jul 2023
    Location
    india
    Posts
    389

    Columns setting in report

    I have a main form in which a sub form is created. In the main form, customer details are entered and in the sub form, shades and meters related to the goods ordered by the customer are entered in 2 fields.While preparing the report of this form, I have set the sub forms of shades and meters in the column option 3 column located in the page setup tab.



    I want that when the report is generated, the heading of shades and meters should be shown before each line of shades and meters. How can this be set? Please see the attachment.

    Thank you..
    Attached Thumbnails Attached Thumbnails sha.png  

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    You put labels in the detail band.?
    Perhaps look on YouTube. Plenty of Access tutorials there on most aspects of Access.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    deepaksharma is offline Competent Performer
    Windows 7 32bit Access 2016
    Join Date
    Jul 2023
    Location
    india
    Posts
    389
    Quote Originally Posted by Welshgasman View Post
    You put labels in the detail band.?
    Perhaps look on YouTube. Plenty of Access tutorials there on most aspects of Access.
    Yes, I added the label but the problem was that the label started getting shown in all three columns whereas I want it to be highlighted only in the first column.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Usually, fields would be horizontal with corresponding labels in header section which would mean 3 sets of labels to align with 3 column pairs.

    Your arrangement calling for vertical labels at left is unorthodox and there is no setting to create. A solution would most likely involve VBA and a temp table.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    deepaksharma is offline Competent Performer
    Windows 7 32bit Access 2016
    Join Date
    Jul 2023
    Location
    india
    Posts
    389
    Quote Originally Posted by June7 View Post
    Usually, fields would be horizontal with corresponding labels in header section which would mean 3 sets of labels to align with 3 column pairs.

    Your arrangement calling for vertical labels at left is unorthodox and there is no setting to create. A solution would most likely involve VBA and a temp table.
    thanks can you suggest any code for this

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    This is one approach.

    Source table:
    ID Shade Meter
    1 red 200
    2 black 100
    3 milky orange 200
    4 white blue 50
    5 light black 400
    6 sky blue 200
    7 red 200
    8 him white 300
    9 light brown 500

    A table named TableTEMP with fields: RowNum, Label, Col1, Col2, Col3.

    Code:
    Code:
    Sub DataToThreeColumns()
    Dim db As DAO.Database, rs As DAO.Recordset
    Dim x As Integer, r As Integer
    Dim s1 As String, s2 As String, s3 As String
    Set db = CurrentDb
    Set rs = CurrentDb.OpenRecordset("SELECT * FROM Table1")
    r = 1
    CurrentDb.Execute "DELETE FROM TableTEMP"
    Do While Not rs.EOF
        For x = 1 To 3
            If x = 1 Then s1 = rs!Shade & vbCrLf & rs!Meter
            If x = 2 Then s2 = rs!Shade & vbCrLf & rs!Meter
            If x = 3 Then s3 = rs!Shade & vbCrLf & rs!Meter
            rs.MoveNext
        Next
        db.Execute "INSERT INTO TableTEMP(RowNum, Label, Col1, Col2, Col3) " & _
            "VALUES(" & r & ",'Shade' & Chr(13) & Chr(10) & 'Meter','" & s1 & "','" & s2 & "','" & s3 & "')"
        r = r + 1
    Loop
    End Sub
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    And I played around with a non-VBA solution. Consider:

    Same source data.

    Query1:
    SELECT ID, "Shade" & Chr(13) & Chr(10) & "Meter" AS Label,
    "Col" & IIf([ID] Mod 3=0,3,IIf([ID] Mod 2=0,2,1)) AS Col,
    [Shade] & Chr(13) & Chr(10) & [Meter] AS Data
    FROM Table1;

    Query2:
    TRANSFORM First(Query1.Data) AS FirstOfData
    SELECT DCount("*","Query1","Col='" & [Col] & "' AND ID<=" & [ID]) AS GrpSeq, Query1.Label
    FROM Query1
    GROUP BY DCount("*","Query1","Col='" & [Col] & "' AND ID<=" & [ID]), Query1.Label
    PIVOT Query1.Col;

    Unfortunately, I expect DCount() to cause slow performance in large dataset. Row numbering can be done with nested subquery but might not be any faster http://allenbrowne.com/ranking.html
    Also, gaps in ID sequence will likely cause uneven columns.
    Last edited by June7; 10-29-2023 at 09:44 PM.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  8. #8
    deepaksharma is offline Competent Performer
    Windows 7 32bit Access 2016
    Join Date
    Jul 2023
    Location
    india
    Posts
    389
    Quote Originally Posted by June7 View Post
    This is one approach.

    Source table:
    ID Shade Meter
    1 red 200
    2 black 100
    3 milky orange 200
    4 white blue 50
    5 light black 400
    6 sky blue 200
    7 red 200
    8 him white 300
    9 light brown 500

    A table named TableTEMP with fields: RowNum, Label, Col1, Col2, Col3.

    Code:
    Code:
    Sub DataToThreeColumns()
    Dim db As DAO.Database, rs As DAO.Recordset
    Dim x As Integer, r As Integer
    Dim s1 As String, s2 As String, s3 As String
    Set db = CurrentDb
    Set rs = CurrentDb.OpenRecordset("SELECT * FROM Table1")
    r = 1
    CurrentDb.Execute "DELETE FROM TableTEMP"
    Do While Not rs.EOF
        For x = 1 To 3
            If x = 1 Then s1 = rs!Shade & vbCrLf & rs!Meter
            If x = 2 Then s2 = rs!Shade & vbCrLf & rs!Meter
            If x = 3 Then s3 = rs!Shade & vbCrLf & rs!Meter
            rs.MoveNext
        Next
        db.Execute "INSERT INTO TableTEMP(RowNum, Label, Col1, Col2, Col3) " & _
            "VALUES(" & r & ",'Shade' & Chr(13) & Chr(10) & 'Meter','" & s1 & "','" & s2 & "','" & s3 & "')"
        r = r + 1
    Loop
    End Sub
    I tried this code many times in my report but I failed every time so I am attaching my file. Please if you adjust this code in it, it will be very kind of you.
    The report in this file is named report2.
    Thank you.
    Attached Files Attached Files

  9. #9
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Code needs to be in a general module, not behind report.

    Report would NOT use multi-Columns settings.

    SQL is missing FROM keyword.

    There is no TableTEMP. Might want to use name GreyTEMP. If this will be a multi-user split db, GreyTEMP must be in frontend. Some developers prefer to create and delete table each time procedure runs instead of just deleting records.

    Probably need to include OfferID in GreyTEMP records so can join to Grey_Offer instead of using Grey_Shade table. Or use GreyTEMP in a linked subreport since you need Grey_Shade data for Sum() calc.

    Data shows only one Offer record but I assume there can be more. This will require adjustment in code to make sure correct OfferID is saved with record. Now that I have some realistic data, I find other issues with suggested code.

    Label caption Shade & Meters needs to be Shade && Meters or use and instead of &.

    Might need to fix report width.

    What is this db for? Selvage is a term for fabric edge.

    Revised code:
    Code:
    Sub DataToFourColumns()
    Dim db As DAO.Database, rs As DAO.Recordset
    Dim x As Integer, r As Integer
    Dim s1 As String, s2 As String, s3 As String, s4 As String, intOID As Integer, strSM As String
    Set db = CurrentDb
    Set rs = CurrentDb.OpenRecordset("SELECT * FROM GREY_SHADE")
    r = 1
    CurrentDb.Execute "DELETE FROM GreyTEMP"
    Do While Not rs.EOF
        intOID = rs!offerid
        For x = 1 To 4
            If Not rs.EOF Then
                strSM = rs!SHADE & vbCrLf & rs!METER
                If intOID = rs!offerid Then
                    If x = 1 Then s1 = strSM
                    If x = 2 Then s2 = strSM
                    If x = 3 Then s3 = strSM
                    If x = 4 Then s4 = strSM
                    rs.MoveNext
                End If
            End If
        Next
        db.Execute "INSERT INTO GreyTEMP(RowNum, OfferID, Label, Col1, Col2, Col3, Col4) " & _
            "VALUES(" & r & "," & intOID & ",'Shade' & Chr(13) & Chr(10) & 'Meter','" & s1 & "','" & s2 & "','" & s3 & "','" & s4 & "')"
        r = r + 1
        s1 = ""
        s2 = ""
        s3 = ""
        s4 = ""
    Loop
    End Sub
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  10. #10
    deepaksharma is offline Competent Performer
    Windows 7 32bit Access 2016
    Join Date
    Jul 2023
    Location
    india
    Posts
    389
    Quote Originally Posted by June7 View Post
    Code needs to be in a general module, not behind report.

    Report would NOT use multi-Columns settings.

    SQL is missing FROM keyword.

    There is no TableTEMP. Might want to use name GreyTEMP. If this will be a multi-user split db, GreyTEMP must be in frontend. Some developers prefer to create and delete table each time procedure runs instead of just deleting records.

    Probably need to include OfferID in GreyTEMP records so can join to Grey_Offer instead of using Grey_Shade table. Or use GreyTEMP in a linked subreport since you need Grey_Shade data for Sum() calc.

    Data shows only one Offer record but I assume there can be more. This will require adjustment in code to make sure correct OfferID is saved with record. Now that I have some realistic data, I find other issues with suggested code.

    Label caption Shade & Meters needs to be Shade && Meters or use and instead of &.

    Might need to fix report width.

    What is this db for? Selvage is a term for fabric edge.

    Revised code:
    Code:
    Sub DataToFourColumns()
    Dim db As DAO.Database, rs As DAO.Recordset
    Dim x As Integer, r As Integer
    Dim s1 As String, s2 As String, s3 As String, s4 As String, intOID As Integer, strSM As String
    Set db = CurrentDb
    Set rs = CurrentDb.OpenRecordset("SELECT * FROM GREY_SHADE")
    r = 1
    CurrentDb.Execute "DELETE FROM GreyTEMP"
    Do While Not rs.EOF
        intOID = rs!offerid
        For x = 1 To 4
            If Not rs.EOF Then
                strSM = rs!SHADE & vbCrLf & rs!METER
                If intOID = rs!offerid Then
                    If x = 1 Then s1 = strSM
                    If x = 2 Then s2 = strSM
                    If x = 3 Then s3 = strSM
                    If x = 4 Then s4 = strSM
                    rs.MoveNext
                End If
            End If
        Next
        db.Execute "INSERT INTO GreyTEMP(RowNum, OfferID, Label, Col1, Col2, Col3, Col4) " & _
            "VALUES(" & r & "," & intOID & ",'Shade' & Chr(13) & Chr(10) & 'Meter','" & s1 & "','" & s2 & "','" & s3 & "','" & s4 & "')"
        r = r + 1
        s1 = ""
        s2 = ""
        s3 = ""
        s4 = ""
    Loop
    End Sub
    I am failing in every endeavor. This is very difficult, I wish you would modify this file.
    So kind of you.

  11. #11
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    1. create GreyTEMP table with fields: RowNum, OfferID, Label, Col1, Col2, Col3, Col4

    2. change report design to NOT use multi-columns

    3. use GreyTEMP as source for a subreport - place a subreport container on main report (try report Footer) and set SourceObject property to a form that has GreyTEMP as RecordSource then set Master/Child Links properties to OfferID - need to include OfferID in main report so these objects can be linked

    4. put code in a general module or behind a form, not behind report

    5. code in form button click event - I don't know where you want this
    Code:
    DataToFourColumns
    DoCmd.OpenReport "Report1", acViewPreview
    What is so difficult about those edits? Exactly what do you not understand?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  12. #12
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    Pulleeeze stop replying to every post with a quote of the entire post. It's rarely necessary. Use reply instead of reply with quote. If you must quote from a lengthy post, copy what you need to quote and paste within quote tags.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  13. #13
    deepaksharma is offline Competent Performer
    Windows 7 32bit Access 2016
    Join Date
    Jul 2023
    Location
    india
    Posts
    389
    thank you micron

  14. #14
    deepaksharma is offline Competent Performer
    Windows 7 32bit Access 2016
    Join Date
    Jul 2023
    Location
    india
    Posts
    389
    Quote Originally Posted by June7 View Post
    1. create GreyTEMP table with fields: RowNum, OfferID, Label, Col1, Col2, Col3, Col4
    i have made changes as far i understand this point, please check it
    Attached Files Attached Files

  15. #15
    deepaksharma is offline Competent Performer
    Windows 7 32bit Access 2016
    Join Date
    Jul 2023
    Location
    india
    Posts
    389
    Another way comes to my mind, suppose there are total 5 columns in the report and the label of shed and meter is being shown in all the five columns, then can there be such coding of if condition in the report load that Labels show in black color in the first column and in white color in other columns due to which those labels will disappear in other columns.

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

Similar Threads

  1. Replies: 2
    Last Post: 06-17-2021, 09:48 AM
  2. Setting a Report Variable with a string
    By Paul H in forum Programming
    Replies: 2
    Last Post: 07-20-2015, 01:12 PM
  3. Setting columns to affect only details
    By trpatrick in forum Reports
    Replies: 1
    Last Post: 03-09-2015, 08:04 AM
  4. Setting named paramater for report
    By gem1204 in forum Reports
    Replies: 1
    Last Post: 07-16-2014, 10:12 PM
  5. Setting default values in columns
    By crownedzero in forum Programming
    Replies: 0
    Last Post: 06-17-2009, 06:45 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