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
7 4986
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): - 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: - Dim frm As Form, ctl As Control, intCounter As Integer
-
Dim varItm As Variant, intNoOfItems As Integer
-
Dim intTest As Integer, strRetVal As String
-
-
Set frm = Forms!frmTest
-
Set ctl = frm!lstSeasons
-
-
intNoOfItems = ctl.ItemsSelected.Count
-
If intNoOfItems = 0 Then Exit Sub
-
-
ReDim astrSeasons(1 To intNoOfItems) 'Redimension Array
-
-
For Each varItm In ctl.ItemsSelected
-
intCounter = intCounter + 1
-
'Store all selected Items in the Arry for later retrieval
-
astrSeasons(intCounter) = ctl.ItemData(varItm)
-
Next varItm
-
-
-
For intTest = LBound(astrSeasons) To UBound(astrSeasons)
-
'retrieve values and build String
-
If Len(strRetVal) = 0 Then
-
strRetVal = strRetVal & astrSeasons(intTest)
-
Else
-
strRetVal = strRetVal & " & " & astrSeasons(intTest)
-
End If
-
Next intTest
-
-
MsgBox strRetVal 'returns completed String
-
'You can assign strRetVal to the Caption of a Label on your Report
-
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.
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): - 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: - Dim frm As Form, ctl As Control, intCounter As Integer
-
Dim varItm As Variant, intNoOfItems As Integer
-
Dim intTest As Integer, strRetVal As String
-
-
Set frm = Forms!frmTest
-
Set ctl = frm!lstSeasons
-
-
intNoOfItems = ctl.ItemsSelected.Count
-
If intNoOfItems = 0 Then Exit Sub
-
-
ReDim astrSeasons(1 To intNoOfItems) 'Redimension Array
-
-
For Each varItm In ctl.ItemsSelected
-
intCounter = intCounter + 1
-
'Store all selected Items in the Arry for later retrieval
-
astrSeasons(intCounter) = ctl.ItemData(varItm)
-
Next varItm
-
-
-
For intTest = LBound(astrSeasons) To UBound(astrSeasons)
-
'retrieve values and build String
-
If Len(strRetVal) = 0 Then
-
strRetVal = strRetVal & astrSeasons(intTest)
-
Else
-
strRetVal = strRetVal & " & " & astrSeasons(intTest)
-
End If
-
Next intTest
-
-
MsgBox strRetVal 'returns completed String
-
'You can assign strRetVal to the Caption of a Label on your Report
-
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.
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
- 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:
- Me![lblTerms].Caption = strRetVal
- Public astrSeasons() as String is declared in a Standard (not Form or Report) Code Module as in:
- Public astrSeasons() as String
- strRetVal should also be Declared in the same manner so that it can be accessed from anywhere in your application, as in:
- Public strRetVal As String
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 - 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:
- Me![lblTerms].Caption = strRetVal
- Public astrSeasons() as String is declared in a Standard (not Form or Report) Code Module as in:
- Public astrSeasons() as String
- strRetVal should also be Declared in the same manner so that it can be accessed from anywhere in your application, as in:
- Public strRetVal As String
__1. Dimension a Public Array of Strings. This Array will contain the items selected from your List Box (lstSeasons): - 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: - Dim frm As Form, ctl As Control, intCounter As Integer
-
Dim varItm As Variant, intNoOfItems As Integer
-
Dim intTest As Integer, strRetVal As String
-
-
Set frm = Forms!frmTest
-
Set ctl = frm!lstSeasons
-
-
intNoOfItems = ctl.ItemsSelected.Count
-
If intNoOfItems = 0 Then Exit Sub
-
-
ReDim astrSeasons(1 To intNoOfItems) 'Redimension Array
-
-
For Each varItm In ctl.ItemsSelected
-
intCounter = intCounter + 1
-
'Store all selected Items in the Arry for later retrieval
-
astrSeasons(intCounter) = ctl.ItemData(varItm)
-
Next varItm
-
-
-
For intTest = LBound(astrSeasons) To UBound(astrSeasons)
-
'retrieve values and build String
-
If Len(strRetVal) = 0 Then
-
strRetVal = strRetVal & astrSeasons(intTest)
-
Else
-
strRetVal = strRetVal & " & " & astrSeasons(intTest)
-
End If
-
Next intTest
-
-
MsgBox strRetVal 'returns completed String
-
'You can assign strRetVal to the Caption of a Label on your Report
-
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 !
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: - Private Sub Command7_Click()
-
Dim frm As Form, ctl As Control, intCounter As Integer
-
Dim varItm As Variant, intNoOfItems As Integer
-
Dim intTest As Integer, strRetVal As String
-
-
'Necessary for Globals
-
Erase astrSeasons()
-
strRetVal = vbNullString
-
-
Set frm = Forms!frmTest
-
Set ctl = frm!lstSeasons
-
-
If ctl.ItemsSelected.Count = 0 Then Exit Sub
-
-
intNoOfItems = ctl.ListCount
-
-
'Simpler to Redimension the Array to the Number of Items since
-
'we do not know how many items are selected at this point. Other
-
'option is to Redimension within the Loop which I do not like to do.
-
ReDim astrSeasons(0 To intNoOfItems - 1) 'Redimension Array to Maximum
-
-
For intCounter = 0 To intNoOfItems - 1
-
If Me![lstSeasons].Selected(intCounter) Then
-
astrSeasons(intCounter) = Me![lstSeasons].Column(1, intCounter)
-
End If
-
Next
-
-
-
-
For intTest = LBound(astrSeasons) To UBound(astrSeasons)
-
'retrieve values and build String
-
If Len(strRetVal) = 0 Then
-
'Remember, astrSeasons was Redim to ctl.ListCount, so no
-
'every element in the Array may not have a value
-
If Len(astrSeasons(intTest)) > 0 Then
-
strRetVal = strRetVal & astrSeasons(intTest)
-
End If
-
Else
-
If Len(astrSeasons(intTest)) > 0 Then
-
strRetVal = strRetVal & " & " & astrSeasons(intTest)
-
End If
-
End If
-
Next intTest
-
End Sub
thank you I've gotten everything working just as I wanted it.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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,
|
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...
|
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,...
|
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...
|
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
|
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...
|
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...
|
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
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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,...
|
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...
| |