Hi gurus!
I have a query result set [band] like the following below: -
Band Country
-
AIR FR
-
Bon Jovi US
-
Oasis UK
-
Blur UK
-
Green Day US
-
Metalica US
-
My final view I want is like the one as below, I have already used VBA to create a temp table [tmpBand] with 3 columns, namely FR, UK & US. -
FR UK US
-
AIR Blur Bon Jovi
-
Oasis Green Day
-
Metalica
-
What I want is to create an array for each country by looping the record rows. For example, the arrray for US would be Bon Jovi, Green Day, Metalica (linebreak instead of having commas). Then fetch the relevant arrays under the correct country columns.
I tried to insert into [tmpBand] but seems not successful. What I should do?
manfred,
Also, are you limiting your records to only those three countries? Any time you expand the number of results, you would be recreating your code.
A cross tab query might work, as Jim implies, but it looks liek you are simply establishing a list of countries, and a list of bands from those countries?
You might have to set up your arrays using multiple recordsets, the first one creating a list of countries, which cycles through each country. The secod record set pulls a list of all those bands assigned to each country.
Then you create your arrays based on those results.
What are you planning to use your arrays for? There might be better ways to get this data depending on how you want to use it.
4 1035
manfred, looks to me like you want to make a crosstab query. In the query designer, right-click in the top half and choose the query type. Band will be the value, Country will be the column heading, but you'll need one more data item to be the row heading. Maybe you've got something else or you could add a counter to your recordset.
Take a look at crosstab queries. They do this very simply.
Jim
manfred,
Also, are you limiting your records to only those three countries? Any time you expand the number of results, you would be recreating your code.
A cross tab query might work, as Jim implies, but it looks liek you are simply establishing a list of countries, and a list of bands from those countries?
You might have to set up your arrays using multiple recordsets, the first one creating a list of countries, which cycles through each country. The secod record set pulls a list of all those bands assigned to each country.
Then you create your arrays based on those results.
What are you planning to use your arrays for? There might be better ways to get this data depending on how you want to use it.
Hi both!
Thanks in advance for yourhelp! Countries and bands will not be limited to these few but won't be more than 15 I suppose and it depends what we inserted. Crosstab view is what I want and I already had a query to make it.
However, for the crosstab I had made with the queries, we have some "layout issues" so I have to look into VBA for making it. For the crosstab view I had, it will happen like the following view. My superior doesn't want to have "blank fields" and prefer those bands aligned to the top and stick to the country. I tried to modify my query and also settings in report but it doesn't appear to what my superior prefers. -
FR UK US
-
Bon Jovi
-
Oasis Green Day
-
AIR Blur Metalica
-
Seems the only solution is to use array. For the above view, it will be like one row of record. So for UK, the array will be [Oasis,vbCrLf,Blur] and insert as one field and [Bon Jovi,vbCrLf,Green Day,vbCrLf, Metalica] for US. The temp table created by VBA already had the country fields as MEMO type. @twinnyfo
I have my pseudo code here: -
Private Sub Command0_Click()
-
Dim db As DAO.Database
-
Dim rs As DAO.Recordset
-
-
Dim sqlStr As String
-
sqlStr1 = ""
-
sqlStr1 = sqlStr1 & "SELECT Band, Country"
-
sqlStr1 = sqlStr1 & "FROM [My-Query]" ' refer to the query for extracting what we need
-
sqlStr1 = sqlStr1 & "WHERE ( Case"
-
sqlStr1 = sqlStr1 & " =" & Me.Case.Value ' condition: Case = Case combo box
-
sqlStr1 = sqlStr1 & " );"
-
-
' another query within this function creates another table [tblTempBandCountry_Case_N], with columns (MEMO type) according to the countries they have
-
-
Dim countryBand
-
-
Set db = CurrentDb
-
Set rs1 = db.OpenRecordset(sqlStr1)
-
If Not (rs1.EOF And rs1.BOF) Then
-
rs1.MoveFirst 'Unnecessary in this case, but still a good habit
-
' LOOPING STARTS
-
Do Until rs1.EOF = True
-
'DO SOMETHING HERE TO CREATE ARRAYS LIKE countryBandFR, countryBandUK, countryBandUS......
-
'THEN countryBandFR="AIR"; countryBandUK="Blur,vbCrLf,Oasis"; countryBandUS="Bon Jovi,vbCrLf,Green Day,vbCrLf, Metalica"
-
'INSERT the countryBand arrays to the temp table [tblTempBandCountry_Case_N] under relevant columns
-
rs1.MoveNext
-
Loop
-
' LOOPING ENDS
-
Else
-
MsgBox "There are no records in the recordset."
-
End If
-
End Sub
-
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Raptor |
last post by:
Hi,
I'm quite new to MySQL and quite impressed by its feature set. I've
also been looking at Interbase and it has a feature that allows a
multidimensional array to be stored in a single field. ...
|
by: Melissa |
last post by:
I have a frontend file named CustomerApp and backend file named CustomerData.
CustomerApp is at C:\Customer Database and CustomerData is at S:\Customer
Database. Could someone help me with the code...
|
by: Raju |
last post by:
Hi all i am Rajendran
I am working as a asp.net programmer.
I am frish to this field so please any of u garify my doubt
I Create array of Textbox Dynamically and not passible to retrieve data...
|
by: dragannis |
last post by:
Hello, I realy need help about this,
I have database that I want to use in my Vb code, and I need to create array from elements of one field from that mdb.
Why : I need to do some calculations...
|
by: =?Utf-8?B?RGFuaWVs?= |
last post by:
Hi,
I have create a class name employee.
Next, i would like to create array for the employee class.
The code as below:
dim eply(5) as employee
when i call eply(0).name="Khrish", an error...
|
by: reap76 |
last post by:
I am trying to create a table that has two columns. If possible I'd like to do that usign two seperate INSERT statements. I am a complete rookie at sql and am learning as I go along. So, please...
|
by: mray |
last post by:
Hello
I have created tables with 20-30 columns and it was manually writing each line of code even when the col type was the same such as
create table testexamp(
id varchar (28).
sample1...
|
by: Claudia Fong |
last post by:
Hi,
How can I create a grid of 20 Columns by 30 Rows using asp.net?
Cheers!
Claudi
*** Sent via Developersdex http://www.developersdex.com ***
|
by: davaahuu |
last post by:
how to create array with audio files?, Is it possible?
|
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: 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: 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,...
|
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...
| |