473,412 Members | 5,385 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,412 software developers and data experts.

Show multiple values for a field in a textbox on a report

Hello,

I have made a form that builds a query which is the recordsource for a report. The form has a listbox to multi-select the term (fall, winter, spring, summer). I would like to make a textbox in the report header that says which terms were selected. For example, if Spring and Winter are selected I want it to say "Spring & Winter". If I bind the textbox to field Term it will only read "Spring". Any help I can get is greatly appreaciated

Thank you
Apr 9 '07 #1
7 4986
ADezii
8,834 Expert 8TB
Hello,

I have made a form that builds a query which is the recordsource for a report. The form has a listbox to multi-select the term (fall, winter, spring, summer). I would like to make a textbox in the report header that says which terms were selected. For example, if Spring and Winter are selected I want it to say "Spring & Winter". If I bind the textbox to field Term it will only read "Spring". Any help I can get is greatly appreaciated

Thank you
__1. Dimension a Public Array of Strings. This Array will contain the items selected from your List Box (lstSeasons):
Expand|Select|Wrap|Line Numbers
  1. Public astrSeasons() As String
__2. Make the appropriate selections from the List Box and place this code wherever you so desire. It will populate the Public Array with your selections and create 1 long String from them:
Expand|Select|Wrap|Line Numbers
  1. Dim frm As Form, ctl As Control, intCounter As Integer
  2. Dim varItm As Variant, intNoOfItems As Integer
  3. Dim intTest As Integer, strRetVal As String
  4.  
  5. Set frm = Forms!frmTest
  6. Set ctl = frm!lstSeasons
  7.  
  8. intNoOfItems = ctl.ItemsSelected.Count
  9. If intNoOfItems = 0 Then Exit Sub
  10.  
  11. ReDim astrSeasons(1 To intNoOfItems)    'Redimension Array
  12.  
  13. For Each varItm In ctl.ItemsSelected
  14.   intCounter = intCounter + 1
  15.  'Store all selected Items in the Arry for later retrieval
  16.   astrSeasons(intCounter) = ctl.ItemData(varItm)
  17. Next varItm
  18.  
  19.  
  20. For intTest = LBound(astrSeasons) To UBound(astrSeasons)
  21.   'retrieve values and build String
  22.   If Len(strRetVal) = 0 Then
  23.     strRetVal = strRetVal & astrSeasons(intTest)
  24.   Else
  25.     strRetVal = strRetVal & " & " & astrSeasons(intTest)
  26.   End If
  27. Next intTest
  28.  
  29. MsgBox strRetVal      'returns completed String
  30. 'You can assign strRetVal to the Caption of a Label on your Report 
  31. on the Open() Event. If you decide to do this, place the code there.
__3. I apologize for a rather incomplete answer, but I am rather pressed for time at the moment. If you need any further explanation, please ask. Either myself or one of the other Moderators/Experts will be glad to help you out.
Apr 9 '07 #2
I am having a little trouble with the implementation.

I made a label on the report called lblTerms, put the entire code in the on_open event of the report and tried to assign strRetVal to lblTerms.Caption but caption is not an option. I suppose that I am not referencing the label correctly but am not sure of the syntax in this situation.

Also, exactly where should I place the code 'public astrSeasons() as string'?

Thanks for your help

__1. Dimension a Public Array of Strings. This Array will contain the items selected from your List Box (lstSeasons):
Expand|Select|Wrap|Line Numbers
  1. Public astrSeasons() As String
__2. Make the appropriate selections from the List Box and place this code wherever you so desire. It will populate the Public Array with your selections and create 1 long String from them:
Expand|Select|Wrap|Line Numbers
  1. Dim frm As Form, ctl As Control, intCounter As Integer
  2. Dim varItm As Variant, intNoOfItems As Integer
  3. Dim intTest As Integer, strRetVal As String
  4.  
  5. Set frm = Forms!frmTest
  6. Set ctl = frm!lstSeasons
  7.  
  8. intNoOfItems = ctl.ItemsSelected.Count
  9. If intNoOfItems = 0 Then Exit Sub
  10.  
  11. ReDim astrSeasons(1 To intNoOfItems)    'Redimension Array
  12.  
  13. For Each varItm In ctl.ItemsSelected
  14.   intCounter = intCounter + 1
  15.  'Store all selected Items in the Arry for later retrieval
  16.   astrSeasons(intCounter) = ctl.ItemData(varItm)
  17. Next varItm
  18.  
  19.  
  20. For intTest = LBound(astrSeasons) To UBound(astrSeasons)
  21.   'retrieve values and build String
  22.   If Len(strRetVal) = 0 Then
  23.     strRetVal = strRetVal & astrSeasons(intTest)
  24.   Else
  25.     strRetVal = strRetVal & " & " & astrSeasons(intTest)
  26.   End If
  27. Next intTest
  28.  
  29. MsgBox strRetVal      'returns completed String
  30. 'You can assign strRetVal to the Caption of a Label on your Report 
  31. on the Open() Event. If you decide to do this, place the code there.
__3. I apologize for a rather incomplete answer, but I am rather pressed for time at the moment. If you need any further explanation, please ask. Either myself or one of the other Moderators/Experts will be glad to help you out.
Jun 13 '07 #3
ADezii
8,834 Expert 8TB
I am having a little trouble with the implementation.

I made a label on the report called lblTerms, put the entire code in the on_open event of the report and tried to assign strRetVal to lblTerms.Caption but caption is not an option. I suppose that I am not referencing the label correctly but am not sure of the syntax in this situation.

Also, exactly where should I place the code 'public astrSeasons() as string'?

Thanks for your help
  1. Caption will not be an Option in the drop down list but you can apply it. In the Open() Event of the Report, place the following line of code:
    Expand|Select|Wrap|Line Numbers
    1. Me![lblTerms].Caption = strRetVal
  2. Public astrSeasons() as String is declared in a Standard (not Form or Report) Code Module as in:
    Expand|Select|Wrap|Line Numbers
    1. Public astrSeasons() as String 
  3. strRetVal should also be Declared in the same manner so that it can be accessed from anywhere in your application, as in:
    Expand|Select|Wrap|Line Numbers
    1. Public strRetVal As String
Jun 13 '07 #4
thank you, this is working very nicely. i have two questions

*when the form is canceled I get an error "can't find the form frmxxxx referred to" from the "Set frm = frmxxx" line. how do I exit the sub properly? there is code in the on_open event that opens a form to select parameters for the query. i also place the code for the array in the report's on_open event

*the array is grabbing the value of column 1(primary key) of the listbox when I would prefer column 2 (fall/spring/winter)

again, thanks for your help

  1. Caption will not be an Option in the drop down list but you can apply it. In the Open() Event of the Report, place the following line of code:
    Expand|Select|Wrap|Line Numbers
    1. Me![lblTerms].Caption = strRetVal
  2. Public astrSeasons() as String is declared in a Standard (not Form or Report) Code Module as in:
    Expand|Select|Wrap|Line Numbers
    1. Public astrSeasons() as String 
  3. strRetVal should also be Declared in the same manner so that it can be accessed from anywhere in your application, as in:
    Expand|Select|Wrap|Line Numbers
    1. Public strRetVal As String
Jun 14 '07 #5
shiznaw
29
__1. Dimension a Public Array of Strings. This Array will contain the items selected from your List Box (lstSeasons):
Expand|Select|Wrap|Line Numbers
  1. Public astrSeasons() As String
__2. Make the appropriate selections from the List Box and place this code wherever you so desire. It will populate the Public Array with your selections and create 1 long String from them:
Expand|Select|Wrap|Line Numbers
  1. Dim frm As Form, ctl As Control, intCounter As Integer
  2. Dim varItm As Variant, intNoOfItems As Integer
  3. Dim intTest As Integer, strRetVal As String
  4.  
  5. Set frm = Forms!frmTest
  6. Set ctl = frm!lstSeasons
  7.  
  8. intNoOfItems = ctl.ItemsSelected.Count
  9. If intNoOfItems = 0 Then Exit Sub
  10.  
  11. ReDim astrSeasons(1 To intNoOfItems)    'Redimension Array
  12.  
  13. For Each varItm In ctl.ItemsSelected
  14.   intCounter = intCounter + 1
  15.  'Store all selected Items in the Arry for later retrieval
  16.   astrSeasons(intCounter) = ctl.ItemData(varItm)
  17. Next varItm
  18.  
  19.  
  20. For intTest = LBound(astrSeasons) To UBound(astrSeasons)
  21.   'retrieve values and build String
  22.   If Len(strRetVal) = 0 Then
  23.     strRetVal = strRetVal & astrSeasons(intTest)
  24.   Else
  25.     strRetVal = strRetVal & " & " & astrSeasons(intTest)
  26.   End If
  27. Next intTest
  28.  
  29. MsgBox strRetVal      'returns completed String
  30. 'You can assign strRetVal to the Caption of a Label on your Report 
  31. on the Open() Event. If you decide to do this, place the code there.
__3. I apologize for a rather incomplete answer, but I am rather pressed for time at the moment. If you need any further explanation, please ask. Either myself or one of the other Moderators/Experts will be glad to help you out.

GOD bless you for being a super genius !
Jun 14 '07 #6
ADezii
8,834 Expert 8TB
thank you, this is working very nicely. i have two questions

*when the form is canceled I get an error "can't find the form frmxxxx referred to" from the "Set frm = frmxxx" line. how do I exit the sub properly? there is code in the on_open event that opens a form to select parameters for the query. i also place the code for the array in the report's on_open event

*the array is grabbing the value of column 1(primary key) of the listbox when I would prefer column 2 (fall/spring/winter)

again, thanks for your help

What exactly do you mean when you say the Form is cancelled? Are you substituting your Form Name for frmTest?

*the array is grabbing the value of column 1(primary key) of the listbox when I would prefer column 2 (fall/spring/winter)
This drastically changes everything, since you cannot apply the same code logic because you are not referencing the Bound Column in the List Box. New code block is listed below:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command7_Click()
  2. Dim frm As Form, ctl As Control, intCounter As Integer
  3. Dim varItm As Variant, intNoOfItems As Integer
  4. Dim intTest As Integer, strRetVal As String
  5.  
  6. 'Necessary for Globals
  7. Erase astrSeasons()
  8. strRetVal = vbNullString
  9.  
  10. Set frm = Forms!frmTest
  11. Set ctl = frm!lstSeasons
  12.  
  13. If ctl.ItemsSelected.Count = 0 Then Exit Sub
  14.  
  15. intNoOfItems = ctl.ListCount
  16.  
  17. 'Simpler to Redimension the Array to the Number of Items since
  18. 'we do not know how many items are selected at this point. Other
  19. 'option is to Redimension within the Loop which I do not like to do.
  20. ReDim astrSeasons(0 To intNoOfItems - 1)  'Redimension Array to Maximum
  21.  
  22. For intCounter = 0 To intNoOfItems - 1
  23.   If Me![lstSeasons].Selected(intCounter) Then
  24.     astrSeasons(intCounter) = Me![lstSeasons].Column(1, intCounter)
  25.   End If
  26. Next
  27.  
  28.  
  29.  
  30. For intTest = LBound(astrSeasons) To UBound(astrSeasons)
  31.   'retrieve values and build String
  32.   If Len(strRetVal) = 0 Then
  33.     'Remember, astrSeasons was Redim to ctl.ListCount, so no
  34.     'every element in the Array may not have a value
  35.     If Len(astrSeasons(intTest)) > 0 Then
  36.       strRetVal = strRetVal & astrSeasons(intTest)
  37.     End If
  38.   Else
  39.     If Len(astrSeasons(intTest)) > 0 Then
  40.       strRetVal = strRetVal & " & " & astrSeasons(intTest)
  41.     End If
  42.   End If
  43. Next intTest
  44. End Sub
Jun 15 '07 #7
thank you I've gotten everything working just as I wanted it.
Jun 18 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Stephen Witter | last post by:
I have a multiple select list and I am trying to post to a page where I have no option to use the request.form or vbscript to iterate through the control. The page is a sql server reporting...
7
by: Rick Caborn | last post by:
Does anyone know of a way to execute sql code from a dynamically built text field? Before beginning, let me state that I know this db architecture is built solely for frustration and I hope to...
7
by: Drew | last post by:
I have a db table like the following, UID, int auto-increment RegNo Person Relation YearsKnown Now here is some sample data from this table,
1
by: Georg Scholz | last post by:
Hello, The class "Control" contains a documented Property "ControlType". So for example, in a form, you can write code like this: Dim c as control set c = me.Controls("textbox1") if...
5
by: kotowskil | last post by:
A report has a subform. The subform is set to datasheet view and its RecordSource is a select query that includes a memo field from the source table. The memo field's Can Grow property is Yes,...
1
by: epigram | last post by:
I'm trying to use the ASP.NET validators to check some client-side business rules. I've got two ASP TextBox controls (call them tbxYear1 and tbxYear2) used to enter a range of years. I've got a...
1
by: BigNasty | last post by:
I have created a report, where there is multiple items with different values in a group that i total up at the end: App 3 App 3 App 2 Com 1 Com 2
19
by: muddasirmunir | last post by:
can any body tell me how to round numbers in in exactly two decimal places i had use a function round(text1.text,2) but whenever there is zere(0) at the end it does not show it for eg for round...
16
by: DAHMB | last post by:
I am not sure if I worded my question correctly. But what I want to do is run a report from two related tables as follows: The first table is called Category - it has one field, called...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.