Results 1 to 7 of 7
  1. #1
    ano is offline Advanced Beginner
    Windows 11 Office 365
    Join Date
    Nov 2023
    Posts
    59

    where to put event code for dynamic crosstab subform

    i have a database with 3 tables,
    table1 contains items price and date is linked to table2,primary key in form
    table2 contains description of item and category
    table3 contains date and used is linked to table1,primary key in form as dataview
    union query day/week/month contains price per day/week/month in form1 linked to table1
    query contains unused items in form2
    crossquery contains used per week in form3


    only form3 has problem because of growing number of weeks to display in top row
    often i get error about ole but i not use ado nor dao just database but i added ado/dao/activex
    if i put the dynamic code in form then i debug.print table1 but not controls (how print controls?)
    if i put the dynamic code in form3 then i not see any table
    the code :
    Option Compare Database


    Private Sub Form_Open(Cancel As Integer)
    Me.Recordset.MoveLast ' ! for table1 rest for table3
    Dim intColCount As Integer
    Dim intControlCount As Integer
    Dim i As Integer
    Dim StrName As String
    On Error Resume Next
    intColCount = Me.Recordset.Fields.Count
    intControlCount = Me.Detail.Controls.Count
    Debug.Print "field:" & intColCount & "::" & intControlCount (result "field:4::10)
    If intControlCount < intColCount Then
    intColCount = intControlCount
    End If
    For i = 1 To intColCount
    StrName = Me.Recordset.Fields(i - 1).Name
    Me.Controls("lblPgHdr" & i).Caption = StrName
    Me.Controls("tbxData" & i).ControlSource = StrName
    Me.Controls("tbxSum" & i).ControlSource = _
    "=Sum([" & StrName & "])"
    Debug.Print "name:" & StrName (4lines : id week item price)
    Next i
    For i = intColCount + 1 To intControlCount
    Me.Controls("tbxData" & i).Visible = False
    Me.Controls("lblPgHdr" & i).Visible = False
    Me.Controls("tbxSum" & i).Visible = False
    Next i
    End Sub

    if i know where to put what event and how to print controls that will help a lot already

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Please start using code tags for code.
    The # icon.
    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
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    Similar threads section at the bottom of this thread

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Print what controls - textboxes? For every record? Just to the immediate window? Why?
    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
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2013 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    Your description is somehow lacking clarity but usually to address the variable\growing number of columns associated with a crosstab query you need to use the actual (crosstab) query as the source object of the subform control (on the main form) instead of a form object.

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  6. #6
    ano is offline Advanced Beginner
    Windows 11 Office 365
    Join Date
    Nov 2023
    Posts
    59

    to understand why coding failed

    Quote Originally Posted by June7 View Post
    Print what controls - textboxes? For every record? Just to the immediate window? Why?
    if u do coding as suggested by several guru and it does not work it can help to understand where to look also called debugging

  7. #7
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Okay, you are printing control name to immediate window after setting label caption and textbox control. Since this result should be viewable on form, what does Debug.Print tell you about the code process?

    You want to change form properties of controls on form to reflect field names generated by CROSSTAB query.

    As Gicu suggested, would be simpler to just use the query as subform container SourceObject.
    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.

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

Similar Threads

  1. Using A Dynamic Crosstab Query On A Form
    By lccrews in forum Forms
    Replies: 9
    Last Post: 09-24-2018, 07:35 PM
  2. Dynamic CrossTab Report from Query
    By ZJGMoparman in forum Programming
    Replies: 1
    Last Post: 08-20-2015, 10:54 AM
  3. Replies: 2
    Last Post: 10-09-2014, 11:37 AM
  4. Dynamic Dates in Crosstab Column Headings
    By air3jxt in forum Queries
    Replies: 5
    Last Post: 03-05-2014, 05:57 PM
  5. Dynamic Column Headers but NOT CROSSTAB
    By jtkjames in forum Queries
    Replies: 1
    Last Post: 07-26-2010, 05:16 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