Solved

How can I get multiple records displayed in one line

Posted on 2014-12-08
8
112 Views
Last Modified: 2014-12-09
Hi

I have a query that returns the below data:

PDCode      PDData                      PortZoneID
W              AP 280   Qu              3
W              AS 264   Qu              3
W              AUH2 282   Qu      3
W              AUH2 282   SG      3
W              BA 278   Qu              3
W              BU1 288   SG              3
W              CO 288   SG              3
W              F1 254   SG              3
W              F2 234   SG              3
W              GA 278   Qu              3

What I would like it to display is:

W AP 280 Qu~AS 264 Qu~AUH2 282   Qu SG~ BA 278   Qu~BU1 288   SG~CO 288   SG~F1 254   SG~F2 234   SG~GA 278   Qu

Is this possible in Access?

Thanks

Ajae
0
Comment
Question by:ajaeclarke
  • 5
  • 2
8 Comments
 
LVL 74

Expert Comment

by:Jeffrey Coachman
Comment Utility
Private Sub Command0_Click()

Put a button on your form to run code like this:

Dim rst As Recordset
Dim strRecords As String
Set rst = CurrentDb.OpenRecordset("YourQuery")
    rst.MoveFirst
    Do Until rst.EOF
       strRecords = strRecords & rst!PDCode & "~" & rst!PDData
        rst.MoveNext
    Loop
   
   Me.txtRecordsString = strRecords

rst.Close
Set rst = Nothing

End Sub

Put a textbox on your form named: txtRecordsString

JeffCoachman
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
Comment Utility
Private Sub Command0_Click()

Dim rst As Recordset
Dim strRecords As String
Set rst = CurrentDb.OpenRecordset("YourQuery")
    rst.MoveFirst
    Do Until rst.EOF
       strRecords = strRecords & rst!PDCode & "~" & rst!PDData
        rst.MoveNext
    Loop
   
   Me.txtRecordsString = strRecords

rst.Close
Set rst = Nothing

End Sub

Open in new window

0
 
LVL 1

Author Comment

by:ajaeclarke
Comment Utility
Thanks JeffCoachman.

I run the code and I get

Run-time error '3061':

Too few parameters.  Expected 2.

and Debug highlights the below:

Set rst = CurrentDb.OpenRecordset("qryPDTOPPRICE")

There are two parameters in the query.  Would this cause this error?
0
 
LVL 74

Accepted Solution

by:
Jeffrey Coachman earned 500 total points
Comment Utility
I think this code will work better:

Dim rst As Recordset
Dim strFirstLetter As String
Dim strRecords As String
Set rst = CurrentDb.OpenRecordset("YourTable")
    rst.MoveFirst
    strFirstLetter = rst!PDCode
    Do Until rst.EOF
       strRecords = strRecords & "~" & rst!PDData
        rst.MoveNext
    Loop
   strRecords = Right(strRecords, Len(strRecords) - 1)
   strRecords = strFirstLetter & " " & strRecords
   Me.txtRecordsString = strRecords

rst.Close
Set rst = Nothing

Open in new window



sample of output in a form and a report is attached
db5.mdb
0
Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

 
LVL 74

Expert Comment

by:Jeffrey Coachman
Comment Utility
Yes, ...you never mentioned parameters in your original question.

This will not work with a parameter if it is not supplied.

But here again, you are not saying what field the parameter is in?, ...how you are specifying the parameter...
is it a simple prompt, ..or is the parameter referencing a form value...
0
 
LVL 1

Author Comment

by:ajaeclarke
Comment Utility
All good....I have made a couple of changes and now you code is working wonderfully.

Thanks for your help.
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
Comment Utility
Great!
;-)

Jeff
0
 
LVL 57

Expert Comment

by:Jim Dettman (Microsoft MVP/ EE MVE)
Comment Utility
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now