P
Pete
I have a label creating program that creates records in a temporary table,
then prints them. The user can enter a range of product numbers into a text
box, e.g. “1-10†and the records are created accordingly. Code is as follows
(I have simplified the SQL string as there are actually more fields).
Dim n As Integer
Dim varRange As Variant
ReDim varRange(2)
Dim strSQL As String
varRange = Split(Me.txtRange, "-")
For n = varRange(0) To varRange(1)
strSQL = "INSERT INTO tmpLabel(nNo) VALUES( '" & n & "')"
DoCmd.SetWarnings (False)
DoCmd.RunSQL strSQL
DoCmd.SetWarnings (True)
Next n
I now wish to enhance this, so that the user can enter comma separated
values as well as ranges, similar to the way that you can enter a range of
pages to print in the Print Dialog e.g.
1-10,15,18,21 would create an array containing 13 elements
1-20,23,25,31-40 would create an array containing 22 elements
I need to split the array on both hyphens and commas, sort the array
elements into numerical order and count the number of elements so that I know
how many times to loop though my INSERT query. I am just not sure what the
best way is to go about doing this is.
All help appreciated.
then prints them. The user can enter a range of product numbers into a text
box, e.g. “1-10†and the records are created accordingly. Code is as follows
(I have simplified the SQL string as there are actually more fields).
Dim n As Integer
Dim varRange As Variant
ReDim varRange(2)
Dim strSQL As String
varRange = Split(Me.txtRange, "-")
For n = varRange(0) To varRange(1)
strSQL = "INSERT INTO tmpLabel(nNo) VALUES( '" & n & "')"
DoCmd.SetWarnings (False)
DoCmd.RunSQL strSQL
DoCmd.SetWarnings (True)
Next n
I now wish to enhance this, so that the user can enter comma separated
values as well as ranges, similar to the way that you can enter a range of
pages to print in the Print Dialog e.g.
1-10,15,18,21 would create an array containing 13 elements
1-20,23,25,31-40 would create an array containing 22 elements
I need to split the array on both hyphens and commas, sort the array
elements into numerical order and count the number of elements so that I know
how many times to loop though my INSERT query. I am just not sure what the
best way is to go about doing this is.
All help appreciated.