i have 2 tables which are linked together
table 1:
[Event] { EventID, EventName, CustomerID }
table 2:
[Customer] { CustomerID, CustomerFirstName, CustomerLastName, AGE }
they are join by CustomerID obvouisly, but i want a report that shows multiple customers in one textbox for one Event.
I.E. Report would look like:
Event: Saturday Customers: Charlie Brown, Alex Maine, Roger Wells
Event: Monday Customers: Dr. Watson, Dr. Green
i would like them to be joined by commas as well, i haven't been able to come up with any function that will combine several rows together of linked ids
any thoughts
10 3586
i have 2 tables which are linked together
table 1:
[Event] { EventID, EventName, CustomerID }
table 2:
[Customer] { CustomerID, CustomerFirstName, CustomerLastName, AGE }
they are join by CustomerID obvouisly, but i want a report that shows multiple customers in one textbox for one Event.
I.E. Report would look like:
Event: Saturday Customers: Charlie Brown, Alex Maine, Roger Wells
Event: Monday Customers: Dr. Watson, Dr. Green
i would like them to be joined by commas as well, i haven't been able to come up with any function that will combine several rows together of linked ids
any thoughts
The default view that you are going to get from any query that returns the records you want is going to be a column. You are wanting to go from column view to a row view, which is not going to be very easy nor intuitive to accomplish!
One approach would be to populate a hidden form (or possibly would require mulitiple hidden forms, don't know as I've not tried this) with the values you wish to concatenate, then draw from this hidden form(s) to populate the values of a label or text box on your report.
The actual code to concatenate (this doesn't include the code to open the hidden form, validate the info, handle errors, etc) would look something like this:
In the on open event of your report: - label1.caption = Forms![YourFormName]![YourTextBoxName] & ": " & Forms![YourFormName]![YourTextBoxName1] & ", " & Forms![YourFormName]![YourTextBoxName2]
etc etc etc.
This vb code would concatenate three text boxes on one form with a : and space between the first two and a , and space between the second two, then assign the value to a label creatively named label1 on your report.
Might be quite a bit easier to just resign yourself to seeing the thing in column view and adjust your report accordingly!
I'll be happy to be corrected by anyone that has any better ideas on how to do this!
Regards,
Scott
i have 2 tables which are linked together
table 1:
[Event] { EventID, EventName, CustomerID }
table 2:
[Customer] { CustomerID, CustomerFirstName, CustomerLastName, AGE }
they are join by CustomerID obvouisly, but i want a report that shows multiple customers in one textbox for one Event.
I.E. Report would look like:
Event: Saturday Customers: Charlie Brown, Alex Maine, Roger Wells
Event: Monday Customers: Dr. Watson, Dr. Green
i would like them to be joined by commas as well, i haven't been able to come up with any function that will combine several rows together of linked ids
any thoughts
One of the way to do it is to write VBA function getting as argument CustomerID and returning concatenated string you are mentioning. The function code - opens a Recordset retrieving all records from [Customer] table where [CistomerID]=<argument passed to the function>
- iterates all records in the Recordset concatenating necessary fields ([CustomerFirstName], [CustomerLastName]) into a string
- returns the string
This function may be used in query as calculated field or form/report control as ControlSource.
Is it possible to join these rows with a select statement or grouping them together in a string value?
Is it possible to join these rows with a select statement or grouping them together in a string value?
Afraid not! I've just worked out a code sample in my test database that will do what you want. To explain:
The process of making this work in your database will be as follows:
Create a query that pulls the values you want to see. I called mine qryEventCustomer, and it had this SQL: - SELECT tblCustomer.CustomerID, tblEvent.EventName, tblCustomer.CustomerFirstname & " " & tblCustomer.CustomerLastName AS Customer
-
FROM tblCustomer INNER JOIN tblEvent ON tblCustomer.CustomerID = tblEvent.CustomerID
-
WHERE (((tblEvent.EventName)="Saturday Morning"));
Next, create an unbound form (I named it frmEventCustomer) in design view. On this form place a listbox named lstEventCustomer. When the wizard comes up, have the listbox look up the values in your qryEventCustomer. Save and close the form.
Next open your vba editor window and on the left-hand side click on the + sign next to the Modules folder. If there are no modules, insert one.
Place this code in the module: - Public Function EventCustomer() As String
-
-
Dim MyArray() As Variant
-
Dim evcust As String
-
Dim cust As String
-
Dim ev As String
-
Dim rs As DAO.Recordset
-
Dim ls As Integer
-
Dim intCounter As Integer
-
Dim list As Integer
-
DoCmd.OpenForm "frmEventCustomer", , , , , acHidden
-
-
Set rs = Forms!frmEventCustomer!lstEventCustomer.Recordset
-
ls = Forms!frmEventCustomer!lstEventCustomer.ListCount
-
With rs
-
.MoveFirst
-
MyArray() = .GetRows(ls)
-
End With
-
-
ev = MyArray(1, 0)
-
cust = MyArray(2, 0)
-
list = 0
-
evcust = ev & ": " & cust
-
For intCounter = 1 To (ls - 1)
-
list = list + 1
-
cust = MyArray(2, list)
-
evcust = evcust & ", " & cust
-
Next
-
-
EventCustomer = evcust
-
DoCmd.Close acForm, "frmEventCustomer", acSaveNo
-
End Function
Next, on your report, create a label named lblEventCustomer. In the OnOpen event of your report, place this code: -
Call EventCustomer
-
Me!lblEventCustomer.Caption = EventCustomer
Save everything, test... Let us know if this works for you, or if you have any further trouble implementing it!
Regards,
Scott
well i have followed what you have done, and you have done a good job, I see the logic behind this process a little bit better, however, I am stuck on an error that needs debugging: it says user function not defined... when i enter in debug mode it has rs As DAO.Recordset
I fiddled around with this making it a string/integer/recordset but i still haven't been able to correct this error
ps: when i do chance DAO.Recordset to recordset it says that rs is a miss match.
Check to make sure you have a reference to the Microsoft DAO Object Library. You do this from Tools > References in the VBA editor.
ok that was a simple fix, however now it's saying Subscripts are out of range with MyArrays() or ev and cust
ok that was a simple fix, however now it's saying Subscripts are out of range with MyArrays() or ev and cust
Had to do a spot of refiguring... for some reason, the ls variable was counting the wrong number of records in the recordset... Anyway, try this instead: -
Public Function EventCustomer() As String
-
-
Dim MyArray() As Variant
-
Dim evcust As String
-
Dim cust As String
-
Dim ev As String
-
Dim rs As DAO.Recordset
-
Dim ls As Integer
-
Dim intCounter As Integer
-
Dim list As Integer
-
DoCmd.OpenForm "frmEventCustomer", , , , , acHidden
-
-
Set rs = Forms!frmEventCustomer!lstEventCustomer.Recordset
-
Erase MyArray
-
With rs
-
.MoveFirst
-
.MoveLast
-
ls = .RecordCount
-
.MoveFirst
-
MyArray() = .GetRows(ls)
-
End With
-
-
ev = MyArray(1, 0)
-
cust = MyArray(2, 0)
-
list = 0
-
evcust = ev & ": " & cust
-
For intCounter = 1 To (ls - 1)
-
list = list + 1
-
cust = MyArray(2, list)
-
evcust = evcust & ", " & cust
-
Next
-
EventCustomer = evcust
-
DoCmd.Close acForm, "frmEventCustomer", acSaveNo
-
Erase MyArray
-
rs.Close
-
-
End Function
Regards,
Scott
ok totally works perfectly now... the problem was that for the array I only had it called for the customername in the form listbox, once i added the event and then modified the array dimension to: - ev = MyArray(0, 0)
-
cust = MyArray(1, 0)
it fixed my subsript out of range problems
THANKS TO ALL!!!
Now i am just going to play with if for a bit so that i dont need to do a form for each event. and maybe even using this tech of storing information I might try running a query store it and place the recordset inside an array and gather that array into a list string
again thank you!
ok totally works perfectly now... the problem was that for the array I only had it called for the customername in the form listbox, once i added the event and then modified the array dimension to: - ev = MyArray(0, 0)
-
cust = MyArray(1, 0)
it fixed my subsript out of range problems
THANKS TO ALL!!!
Now i am just going to play with if for a bit so that i dont need to do a form for each event. and maybe even using this tech of storing information I might try running a query store it and place the recordset inside an array and gather that array into a list string
again thank you!
Glad it's working for you! and you're welcome.
Regards,
Scott
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Paul .V. |
last post by:
I have a report which I call to print from a form. For security
reasons I have created a global variable:
Const Company = "This Test Company"
I call that constant whereever I want the company...
|
by: kmnotes04 |
last post by:
I have a data entry form that contains drop-down lists such as
'Assigned to:' with a list of staff member names. Those names end up as
numerical codes in the main table ('ProjectInfo') of the...
|
by: Rodrigo DeJuana |
last post by:
Howdy,
I'm new to this .net stuff and really have little to no training. Im trying
to create a new page for a web form, so i have been pretty much jsut coping
code. I having some issue with...
|
by: IRAS Blues |
last post by:
Hi all,
I've got a form that consists of a bunch of textboxes and also file
upload inputs. For both sets of fields, I need to be able to add in
additional elements on the fly. This is done by an...
|
by: justin tyme |
last post by:
Hello Experts!
I would like to combine (which may not be the correct technical term) two
text fields from the same table in a query. Specifically, text field A and
text field B are both lists of...
|
by: John Smith |
last post by:
I have two text fields in a table. One is Height, one is width. Some
examples of what might be each field:
Height Width
35' 35'
8' 6'
4 to 6...
|
by: nallen05 |
last post by:
Is there a standardized recommendation for combining names and
namespaces into a single URI?
I found a post on the Stylus Studio forum asking the same question,
the response was "use James...
|
by: H |
last post by:
Hi,
I have the following address fields in a table:
flat_number
house_name_or_number
street
village
postal_town
county
postcode
|
by: robert.waters |
last post by:
I have an Access database frontend linked via ODBC to a large
(gigabytes) mysql database.
I need to view a large amount of data in a a textbox (variable up to
300K), but I receive a 'there isnt...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
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: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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:
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...
|
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,...
|
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...
| |