473,385 Members | 1,872 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,385 software developers and data experts.

Semicolon Generated List

Breezwell
Hi everyone,

Here is a little something I have been trying to implement, however I am not sure I am on the right path.

To start, I have a query of product numbers such as the following:

196334
194778
196225
....

What I would like to do is create a semicolon separated list of these numbers such as:

196334;194778;196225

These numbers, I am assuming, would need to be pulled from my query and stored in an array so that I could present this list in, say, a MsgBox text field, so the user could select the entire list and paste the list into another text control.

I am not sure how to pull this data from my query and put the product codes into the array to achieve the desired result. I am thinking that once I have this array, I can use strconv() to create the actual string representation?

Thanks for any pointers or suggestions.
Nov 9 '08 #1
7 2948
FishVal,

Thanks for the reply.

The link you sent referring to ADO is great and I managed to get to the point of generating the output in the Immediate window with the following code:

Private Sub Command2_Click()

Dim rstNames As ADODB.Recordset
Dim varCodes As Variant

Set rstNames = New ADODB.Recordset
With rstNames
.Source = "[names]"
.ActiveConnection = CurrentProject.Connection
.CursorType = adOpenKeyset
.LockType = adLockOptimistic
.Open
End With

varCodes = rstNames.GetRows(rstNames.RecordCount, , "ID")
rstNames.MoveFirst

For varrows = 0 To UBound(varCodes, 1)
For varCols = 0 To UBound(varCodes, 2)
Debug.Print varCodes(varrows, varCols) & ";"
Next
Next
End Sub

I get the following output in the Immediate window:

1;
2;
3;
4;

This is exactly what I need. Problem is, I can't figure out how to get this output into a variable that can be displayed in a forms text box. Again, I am thinking arrays are the way to go, but all the examples I have seen simply dump the output to the Immediate Window.

Thanks again for the help so far.
Nov 10 '08 #3
FishVal
2,653 Expert 2GB
Array is certainly way to go.
And you have already one - varCodes.
Now you could use Join() function to merge the array elements with delimiter.

Kind regards,
Fish
Nov 10 '08 #4
Well, I tried some simple array-to-string conversions with the join() method and it seemed to work just fine. So, I tried the following in my code and recieved Runtime Error 3219: Operation is not allowed in this context. The error is showing up on the line:

varCodes = rstGroupCodes.GetRows(rstGroupCodes.RecordCount, , "GroupCode")

This is bizzare as this is the same code that worked previously.



' Generate list of group codes in semicolon delimited list
' ************************************************** *************
Private Sub btnGetGroupCodes_Click()

Dim varCodes As Variant ' holds array returned by getrows method
Dim varList As Variant ' holds array string generated from join method
Dim rstGroupCodes As ADODB.Recordset ' recordset object variable

Set rstGroupCodes = New ADODB.Recordset

' set recordset properties
With rstGroupCodes
.Source = "qryBucketSearchSelling"
.ActiveConnection = CurrentProject.Connection
.CursorType = adOpenKeyset
.LockType = adLockOptimistic
.Open
End With

' generate array of group codes from recordset with getrows()
varCodes = rstGroupCodes.GetRows(rstGroupCodes.RecordCount, , "GroupCode")


' create semicolon delimited list of group codes from array varCodes
varList = Join(varCodes, " ; ")

' clean up connection
rstGroupCodes.Close
Set rstGroupCodes = Nothing

End Sub


Now, maybe I am trying to be a little too simplistic with my code, but it would seem that if Join() worked on a simple array, it should work on the varCodes arrray?

Thanks
Nov 10 '08 #5
FishVal
2,653 Expert 2GB
Well, I tried some simple array-to-string conversions with the join() method and it seemed to work just fine. So, I tried the following in my code and recieved Runtime Error 3219: Operation is not allowed in this context. The error is showing up on the line:

varCodes = rstGroupCodes.GetRows(rstGroupCodes.RecordCount, , "GroupCode")
I guess RecordCount may be not available at this point - recordset opening is not a solid synchronous operation. To enforce it to "count records" perform
Expand|Select|Wrap|Line Numbers
  1. rstGroupCodes.MoveLast
  2. rstGroupCodes.MoveFirst
  3.  
before using RecordCount property.

Now, maybe I am trying to be a little too simplistic with my code, but it would seem that if Join() worked on a simple array, it should work on the varCodes arrray?
Well...
It doesn't seem to work with 2-dimensional array.
You could
  • Copy 2D array column to 1D array.
  • Use Recordset.GetString method instead of Recordset.GetRows.

Regards,
Fish
Nov 10 '08 #6
ADezii
8,834 Expert 8TB
Well, I tried some simple array-to-string conversions with the join() method and it seemed to work just fine. So, I tried the following in my code and recieved Runtime Error 3219: Operation is not allowed in this context. The error is showing up on the line:

varCodes = rstGroupCodes.GetRows(rstGroupCodes.RecordCount, , "GroupCode")

This is bizzare as this is the same code that worked previously.



' Generate list of group codes in semicolon delimited list
' ************************************************** *************
Private Sub btnGetGroupCodes_Click()

Dim varCodes As Variant ' holds array returned by getrows method
Dim varList As Variant ' holds array string generated from join method
Dim rstGroupCodes As ADODB.Recordset ' recordset object variable

Set rstGroupCodes = New ADODB.Recordset

' set recordset properties
With rstGroupCodes
.Source = "qryBucketSearchSelling"
.ActiveConnection = CurrentProject.Connection
.CursorType = adOpenKeyset
.LockType = adLockOptimistic
.Open
End With

' generate array of group codes from recordset with getrows()
varCodes = rstGroupCodes.GetRows(rstGroupCodes.RecordCount, , "GroupCode")


' create semicolon delimited list of group codes from array varCodes
varList = Join(varCodes, " ; ")

' clean up connection
rstGroupCodes.Close
Set rstGroupCodes = Nothing

End Sub


Now, maybe I am trying to be a little too simplistic with my code, but it would seem that if Join() worked on a simple array, it should work on the varCodes arrray?

Thanks
Now, maybe I am trying to be a little too simplistic with my code, but it would seem that if Join() worked on a simple array, it should work on the varCodes arrray?
FishVal gave you the correct answer, it only works with Single Dimension Arrays.
Nov 11 '08 #7
Okay, thanks guys for the feedback.

I will keep trying with some other array ideas. If I can find the time, and get this to work, I will post my success.

Thanks again.
Nov 18 '08 #8

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

Similar topics

11
by: fritz | last post by:
Hi, When I look through the "javascript bible" I don't find any example scripts that have lines with ending semicolons. However when I peruse this newsgroup I find that sometimes there are ending...
4
by: yaffa | last post by:
dear folks, i have the following lines of python code: couch = incident.findNextSibling('td') price = couch.findNextSibling('td') sdate = price.findNextSibling('td') city =...
9
by: Russ | last post by:
Here is a question for the programming language historians out there. Can anyone tell me which "major" language first introduced the convention of terminating each statement with a semicolon? Was...
64
by: Merrill & Michele | last post by:
#include <stdio.h> int main(void) { int i = 0; ++ i; ++ i; printf("i equals %d\n", i); return 0; } I've been trying to determine the great and manifold uses of the semicolon
3
by: Dan | last post by:
I'm writing a record from an asp.net page to SQL Server. After the insert I'm selecting @@identity to return the ID of the record that I just wrote. It worked fine until I typed a semicolon into...
7
by: MattyWix | last post by:
Hi, How can I pass a semicolon or a comma as a macro argument. I wish to build an expression that in some cases has a comma - eg building a list of members for a structure, but in other...
1
by: Lawrence San | last post by:
According to a JavaScript debugger (Firebug), and to a JS lint, this is fine: function recalc(){deriv = 6;} But, if I've assigned the function to a variable like this: var bells =...
3
by: Peter Michaux | last post by:
Hi, These first three links say that when reading document.cookie the name-value pairs are separated by semicolons and they show examples like "name=value;expires=date" where there is clearly...
9
by: David Trimboli | last post by:
On a couple of my pages http://www.trimboli.name/rune/goblinmagic.html http://www.trimboli.name/rune/labyrinth.html I've got a number of definition lists concerning "Points Spent" and "Points...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
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...
0
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
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:
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...
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
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...

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.