473,498 Members | 1,639 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Recordset And Then Looping Through, Display Results TextBox Each Line

gcoaster
117 New Member
Hello Group

I need help,

I need to use an [Event Procedure] to show results values from a table and display in a unbound textbox on a form. the results from each column in the table need to be on seperate lines, a break if you may. Here is the code I have so far.

In colKeyword Column In tblKEYWORDS table match what i select in cboCategory Combo drop down box and populate txtcategories textbox on form

What I would like to do is show All colKeyword results in textbox [txtcategories] and display each result on its own line!

example

entry1
entry2
entry3
entry4


Thank you


Earlier thread 'Access 2010 - DLoolup Show Results Values in Texbox on its own line multiple columns'
Mar 27 '14 #1
9 6283
jimatqsi
1,271 Recognized Expert Top Contributor
gcoaster,
Your question is not at all clear. At times you seem to be confusing "column" with "row." I doubt that "each column in the table need to be on separate lines", it would be a very odd way to collect the data. Assuming you mean each row in the table would need to be on separate lines.

Further, you say "What I would like to do is show All colKeyword results " after you also said "In colKeyword Column In tblKEYWORDS table match what i select in cboCategory " ... in that case, colKeyword will be only one value, the value=to what is in cboCategory, so all colKeyword results will be the same.

Read your post carefully and rewrite your request to reflect what you actually want so that someone who has no idea what you're doing will get the idea. The table name is tblKEYWORDs; the column to search is colKeyword; what is the name of the column you want to show for all rows that have colKeyword=cboCategory?

I'm going to take a shot in the dark here and suggest what you really want to populate is a list box and not a textbox. If you make a list box and set the data source with the SQL code as shown below I think that may give you what you want. Make a listbox called Results_list and in the AfterUpdate event for the combo box cboCategory put this code:

Expand|Select|Wrap|Line Numbers
  1. me.Results_list.rowsource="Select [name of column you want to show] from tblKEYWORDS where colKeyword='" & me.cboCategory & "'"
  2.  
That will change the content of the list box every time you change the combo box. You might want to add a sort order.

Jim
Mar 27 '14 #2
Seth Schrock
2,965 Recognized Expert Specialist
This question is an offshoot from Access 2010 - DLookup Show Results Values in Textbox on its own line multiple columns. So your code would be something like this.
Expand|Select|Wrap|Line Numbers
  1. Dim db As DAO.Database
  2. Dim strRst As String
  3. Dim rst As DAO.Recordset
  4. Dim strKeywords As String
  5.  
  6. 'Setup the recordset
  7. Set db = CurrentDb
  8. strRst = "SELECT colKeyword FROM tblKEYWORDS WHERE cboCategory = '" & txtcategories & "'"
  9. Set rst = db.OpenRecordset(strRst, dbOpenDynaset)
  10.  
  11. 'Loop through all the records
  12. Do While Not rst.EOF
  13.     strKeywords = rst!colKeyword & vbCrLf
  14. Loop
  15.  
  16. 'Set the textbox value
  17. Me.txtKeywords = strKeywords
Without further information as to where this is going, I can't help you as to which event this code should go in, but this should get you started.
Mar 27 '14 #3
zmbd
5,501 Recognized Expert Moderator Expert
Jim and Seth have been very gracious with their time; however, gcoaster – we’re not a code writing service.

Therefor, at this point I am going to have to ask that you provide a clear, specific question and provide any code that you’ve already attempted to solve that issue, then we’re certainly here to help.
Mar 27 '14 #4
gcoaster
117 New Member
Hello Zmbd,
I understand you are not a coding service.
And i am grateful for the time from everyone.

its extremely hard for me to put all of this in words properly.
I apologize
Apr 12 '14 #5
gcoaster
117 New Member
Ok, I will do my best!!

I have a TABLE
table is named | tblKeywords
there are 3 columns in the table
[1] ID
[2] colKeyword
[3] colCategory

I have a FORM
The Form is named | frmMain

On frmMain i have a dropdown combo box and its named | cboCategory

on frmMain i also have a unbound text field set to rich format
and it is named |txtKeywords


Would i am trying to do is select a category from cbocategory and then have display all of the entries in tblKeywords where the cboCategory selection is matched

For instance i select Mens Shoes
and then in the box it shows all of the results from table
one on each line.

tblKeywords - colCategory, colKeyword
frmMain - txtKeywords


Example of data in table - colCategory=mens shoes colKeyword=business shoes

I would love txtKeywords to display

business shoes
best shoes for men
casual mens shoes
designer mens shoes


Thank you ALL!
Apr 12 '14 #6
gcoaster
117 New Member
Got this to work in Access 2010!

after much drama here is the code that works!

Expand|Select|Wrap|Line Numbers
  1. Private Sub cboCategory_AfterUpdate()
  2.   Dim dbs As DAO.Database, rst As DAO.Recordset, StrKeywords As String
  3.  
  4.   Set dbs = CurrentDb
  5.  
  6.   Set rst = dbs.OpenRecordset("SELECT colKeyword " _
  7.   & "FROM tblKeywords " _
  8.   & "WHERE colCategory='" & Me.cboCategory & "'")
  9.   If Not rst.EOF Then
  10.     Do
  11.       StrKeywords = StrKeywords & rst![colKeyword] & "<br>"
  12.       rst.MoveNext
  13.     Loop Until rst.EOF
  14.     Me.txtKeywords = Left(StrKeywords, Len(StrKeywords) - 4)
  15.   End If
  16. End Sub
Thank you everyone! Happy Easter... JESUS HAS RISEN!
Apr 12 '14 #7
zmbd
5,501 Recognized Expert Moderator Expert
Hello,
Now that makes better sense (^_^)

and I'm glad to see that you worked it out... if you had started out with your post #6 here we would have sent you the following insite articles

Sorry, I'm babysitting at a friends house today; thus, I don't have my normal set of tools and the laptop has a realy small keyboard (and a missing key or two ROTFL); however, I think that if you will read thru the following Multiple Combobox Filter with Clear Option

and

How to select Records in an Access Subform from a Combo Box

you will certainly find other code in our insights articles that you can use/modify so I highly advise a read thru of the titles.

Our Pleasure, Happy Easter to you Too: "Christ Is Risen! Hallelujah!"
Apr 13 '14 #8
NeoPa
32,557 Recognized Expert Moderator MVP
I was amused and very pleased to see that, once again, when someone goes to the trouble (and it is trouble. It can be really hard to express problems sometimes.) of expressing the situation clearly and in precise detail for the experts so that they can help, they naturally sort things out a lot more clearly in their own heads. Often, as in this case clearly, it leads very shortly to the OP coming up with their own answer without further help.

This isn't about criticism of not doing that to start with. It's much harder than it seems. It's just that much more benefit comes from it than most people realise. Congratulations on getting your answer GCoaster.
Apr 13 '14 #9
jimatqsi
1,271 Recognized Expert Top Contributor
gcoaster,
Congratulations on working out your own solution. Way to go.

Now I'd like to encourage to try to do it again but use a list box for your results instead of a text box. I say that as one very late to understand the virtues of list boxes. I avoided using them for years.

You can do the same thing with less code and get some follow-on processing available through the event handling of the list box. For instance, your user could click on "casual mens shoes" and make something happen.

Just a thought to extend your understanding of the tools available.

Jim
Apr 14 '14 #10

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

Similar topics

4
4068
by: Roy Adams | last post by:
Hi posting again because no answer to previous.. tring to loop through a recordset and update a record, thing is it only updates the first record in the table rather than searching through the...
7
14681
by: Lauren Quantrell | last post by:
I have a table with three columns. One of the columns contains text output data nvarchar(500), one of them contains a filename nvarchar(50), one of the columns is a bit to record if it has been...
6
4613
by: RC | last post by:
My code below will loop through all the records in the table, and when the if statement is true it goes to the ***Me.ContainerNumberProductsTable = GETContainerNumber.Value*** bit like should but...
6
6593
by: Maziar Aflatoun | last post by:
Hi, I have a little application that reads a text file line-by-line and processes each line depending on the CVS values. Now I want to change my program to capture this from a textbox. How do...
20
3023
by: Stewart Graefner | last post by:
Here is a chunk of code that works for an individual record. It evaluates dates and checks or unchecks boxes as it goes along. It may not be pretty but it works. What my problem is that I need it...
7
5458
by: Ken | last post by:
Hi All - I have a filtered GridView. This GridView has a check box in the first column. This check box is used to identify specific rows for delete operations. On the button click event I...
7
1661
by: Mick Walker | last post by:
I have a collection of objects populated from a SQL Server (sorted descending). Each of these object has a date field. I need a way to loop through these object starting from the newest entry,...
0
1571
Jerry Maiapu
by: Jerry Maiapu | last post by:
I HAVE THIS Sql Query ( qrysummary) : SELECT .Salutation, ., ., IIf((WorkingDays(!!, !!))-()<0,0, (WorkingDays(!!,!!))-()) AS , IIf(IsNull(),0,) AS , .SumOfHrtMintNoAOT,
5
1886
by: bigukfan | last post by:
I am producing a statistic for one of the managers at work concerning hospital patients. I have a database with about 120 tables, some of which relate to a set of patients. All the table names I am...
0
7125
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7165
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
7205
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...
1
6887
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
7379
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
5462
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
3093
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3085
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
291
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.