Results 1 to 6 of 6
  1. #1
    shabbaranks is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Oct 2011
    Posts
    162

    Output vba\sql to subform when I initially wrote it for a listbox

    Hi guys,



    Im in a bit of a position. I wrote some VBA which outputted the results of mysql to a listbox as per the below code:
    Code:
        Case "Current User"
             MySQL = "SELECT TimesheetTable.sUser, TimesheetTable.Activity, TimesheetTable.Hours, TimesheetTable.Project, TimesheetTable.[Task Date], TimesheetTable.Description FROM TimesheetTable "
             MySQL = MySQL & "WHERE ((TimesheetTable.sUser)= '" & [Forms]![TotalHours_Frm]![CurrentUser] & "') AND ((TimesheetTable.[Task Date])>=[Forms]![TotalHours_Frm]![TotalHours_Fromtxtbox] AND "
             MySQL = MySQL & "(TimesheetTable.[Task Date])<=[Forms]![TotalHours_Frm]![TotalHours_Totxtbox]) AND ((TimesheetTable.Project) Like '*" & [Forms]![TotalHours_Frm]![ProjectRef_txtbox] & "*')"
                
                Me.TotalHrs_Listbox.RowSourceType = "table/query"
                Me.TotalHrs_Listbox.ColumnCount = "6"
                Me.TotalHrs_Listbox.ColumnWidths = "3.5cm;3.5cm;1.50cm;6.5cm;2.25cm;7.5cm;"
                Me.TotalHrs_Listbox.RowSource = MySQL
                
                        
           
        End Select
    Is there an easy way to change the listbox to a subform and then carry on from where I left off? The reason being I am trying to tally a column not realising that the listbox wasnt the best option for this method.

    Thanks in advance!!

  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
    Sure, you just set the RecordSource property of the subform instead of the RowSource property of the listbox. You'd have to create it. You could loop the listbox to sum up a column too.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    shabbaranks is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Oct 2011
    Posts
    162
    Hi,

    I ws trying to get the sum of a column in the listbox but what ever I do, Access seems to think that the value is null as per below:

    Code:
    ? me.TotalHrs_Listbox.Column(2)
    Null
    ? me.TotalHrs_Listbox.Column(1)
    Null
    ? me.TotalHrs_Listbox.Column(3)
    Null
    Where as you can see from this image http://imgur.com/rOgKG its not - there is data in the listbox. the code is here

    Code:
                For counter = Me.TotalHrs_Listbox.Column(2).ListCount - 1 To 0 Step -1
                sum = sum + Me.TotalHrs_Listbox.ColumnCount
                Next counter
                Me.TotalHours_txtbox.Value = sum
    Thanks

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    This is only adding selected items in a multi-select listbox, but see if how I'm referring to the value works for you:

    Code:
      For Each varItem In ctl.ItemsSelected
        curTotal = curTotal + ctl.Column(4, varItem)
      Next varItem
      Me.txtTotalPayments = curTotal
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    shabbaranks is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Oct 2011
    Posts
    162
    This ones working, there were a couple of issues. I had a combo which referenced different columns depending on selection. Ironed that out and used the code

    Code:
                For counter = Me.TotalHrs_Listbox.ListCount - 1 To 0 Step -1
                sum = sum + Me.TotalHrs_Listbox.Column(2, counter)
                Next counter
                Me.TotalHours_txtbox.Value = FormatNumber(sum, 2)
    And now everything is hunky dorey!

    Thanks

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Happy to help.
    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. Subform to show records of Listbox
    By gbmarlysis in forum Forms
    Replies: 5
    Last Post: 02-27-2012, 04:03 PM
  2. output file name
    By AdrianoG87 in forum Reports
    Replies: 4
    Last Post: 11-03-2011, 06:20 PM
  3. .txt output from report
    By dhopper in forum Reports
    Replies: 1
    Last Post: 08-05-2011, 12:01 PM
  4. Replies: 3
    Last Post: 06-22-2011, 08:51 AM
  5. Replies: 1
    Last Post: 03-15-2011, 03:53 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