473,407 Members | 2,312 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,407 software developers and data experts.

Need List Box to appear like TxxtBox in Report

RobH
56
I have a report that has some Listboxes - due to the nature that these can do SQL Queries within themselves but they appear with boxes around them and the content does not wrap.

How Can I make a listbox appear like a textbox.?
Sep 21 '07 #1
5 1638
Jim Doherty
897 Expert 512MB
I have a report that has some Listboxes - due to the nature that these can do SQL Queries within themselves but they appear with boxes around them and the content does not wrap.

How Can I make a listbox appear like a textbox.?
Going on your brief posting you could iterate through the list provided by your listbox concatenating and assigning each data value to a string variable using ITEMDATA in a loop.

Each data value could be separated for instance with a comma and space between each value. You would then strip off the last comma and space at the end of the loop and assign the whole value of the variable to the textbox

My Assumptions
You have a single listbox called MyListBox that you requery each time in the Detail_Print event of your report and that this listbox has a single (1) column list
You have a single unbound textbox Called MyTextBox placed on the detail section which will be used to display the listbox contents.
You are not too concerned with efficiency (in effect you are handling this data twice! once to return and display in a listbox and then two to loop and display the same data in a textbox.) I assume you will hiding the listbox? given the textbox will be displaying its content.

The Code to make this work in the DETAIL_PRINT event of the report

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
  3. Me!MyListBox.Requery
  4. Dim i As Integer
  5.     Dim GetList As String, strData As String
  6.     ' Iterate through all entries.
  7.     For i = 0 To MyListBox.ListCount - 1
  8.         GetList = Me!MyListBox.ItemData(i)
  9.         ' Add a comma and space to each concatenated data value.
  10.         strData = strData & GetList & ", "
  11.     Next i
  12.     If Len(strData) = 0 Then
  13.         Me!MyTextBox = ""
  14.     Else
  15.     'strip off the last space and comma and display in text box.
  16.         Me!MyTextBox = Left(strData, Len(strData) - 2)
  17.     End If
  18. End Sub
  19.  
Hope this helps you

Regards

Jim
Sep 21 '07 #2
NeoPa
32,556 Expert Mod 16PB
Rob,
You're a full member now. It would be nice if you could phrase your question a little more clearly. It's hard enough to find the answers sometimes, but we shouldn't need to spend so much time trying to understand what the question means.

MODERATOR.
Sep 21 '07 #3
RobH
56
Wow I see what you mean about slowing it down..
If you have a bunch on the screen it will take a while.

Thanks.
Sep 21 '07 #4
RobH
56
Alternatively is there a way (in vb) to store the result of the SQL statement into the Textbox..

eg:
Expand|Select|Wrap|Line Numbers
  1. Me.MyTextBox = DoCmd.RunSQL "Select............"
  2.  
  3.  
  4. or
  5.  
  6.  
  7. Dim sqlvalue as string
  8. sqlvaue = Docmd.RunSQL "Select............"
  9. me.MyTextBox = sqlvalue
  10.  
Sep 21 '07 #5
Jim Doherty
897 Expert 512MB
Alternatively is there a way (in vb) to store the result of the SQL statement into the Textbox..

eg:
Expand|Select|Wrap|Line Numbers
  1. Me.MyTextBox = DoCmd.RunSQL "Select............"
  2.  
  3.  
  4. or
  5.  
  6.  
  7. Dim sqlvalue as string
  8. sqlvaue = Docmd.RunSQL "Select............"
  9. me.MyTextBox = sqlvalue
  10.  
Rob

I'm afraid you are way off the mark with that one I understand your thought process, but you are talking about the return of recordsets and how you deal with the physical data returned as a two dimensional matrix.

Docmd.RunSQL whilst incredibly useful is not the panacea to all it runs 'Action' or data definition queries
INSERT INTO, DELETE, SELECT...INTO, UPDATE, CREATE TABLE, ALTER TABLE, DROP TABLE, CREATE INDEX, or DROP INDEX statements

Note.... NOT.... SELECT statements (which return datasets and from which your listboxs rely for their data)

So in short...you simply cannot throw a multi column two dimensional recordset into a string variable

When I mentioned you were handling the data twice that is correct. Your answer lies optimally in opening up a RECORDSET in Code and looping through the recordset, grabbing datavalues as you loop through the recordset (in much the same way as my earlier example to you) concatenating the results in whichever way befits your requirement ie: is it one column or two or maybe more columns that you wish to grab ..... if so how do you intend to equally space datavalues if the data is to be dumped into the textbox. IF there is more than one column and so on.

It is entirely possible for you to open a recordset loop through it and assign the result to the textbox without ever having any listbox on your report you merely have to understand the concept of recordsets generally, how they get opened in memory, how you loop through and grab their values importantly and especially within the context of what you wish to do currently how to massage and manipulate that data to FILL the textbox with it.

Unfortunately every method or property has its limitations scoped to the intention of, as in this case.......the 'control' as we appreciate that 'actually' what you are trying to do is make a textbox into a listbox.

You will probably think this is way too much work to do to achieve something which, and I would agree with you seems like a simple request.

The elegance of programming mimicry very often lies in the skilful understanding of workarounds because, as you quite rightly point out, a listbox doesnt grow and behave like a textbox by default.

Have a look at the openrecordset method in Access help

I hope this helps you a bit further

Regards

Jim
Sep 21 '07 #6

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

Similar topics

3
by: ChrisWinterscheid | last post by:
We are running DB2 8.1 on AIX 5.2. DB2level shows: DB21085I Instance "db2inst1" uses "32" bits and DB2 code release "SQL08016" with level identifier "02070106". Informational tokens are "DB2...
3
by: google | last post by:
I have a database with four table. In one of the tables, I use about five lookup fields to get populate their dropdown list. I have read that lookup fields are really bad and may cause problems...
3
by: ChadDiesel | last post by:
Hello everyone. I need some advice on table structure for a new project I've been given. One of our customers sends us an Excel spreadsheet each week containing their order. Currently, someone...
2
by: Marcus | last post by:
I have a list box and a text box. I have populated the list box with names of reports from the tblTable1.RptList column. I want to be able to click on one report (in the list box), and have...
7
by: ChadDiesel | last post by:
Hello everyone, I'm having a problem with Access that I need some help with. The short version is, I want to print a list of parts and part quantities that belong to a certain part group---One...
2
by: Eric | last post by:
I have an Access 95 database. This database has run for years and now is giving me a problem. When opened, the switchboard works fine and the database functions. However, when I close the...
1
by: wcamp | last post by:
I would like a "field list" to appear in report design. Clicking the "filed list" icon nothing happens. Have tried dozens of ways to get a "field list", so far no luck! Have created over 5 ACCESS...
5
by: jonosborne | last post by:
Hi, i have managed to filter a report based on selections made in a list box but am totally confused with a message box that appears everytime i run my report. Let me explain (i apologise for...
1
by: vikjohn | last post by:
I have a new perl script sent to me which is a revision of the one I am currently running. The permissions are the same on each, the paths are correct but I am getting the infamous : The specified...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
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.