2 parts - 1) Sorting & 2) Control array

D

DaBartman

1) Need to be able to sort short lists of items where it is inconvienent to
create a table abnd have the table sort the items and 2) Anyone have any work
arounds for creating an array of controls on a form? I used to do this with
Visual Basic, but Access will not allow this.

Thanks,
Bart
 
A

Arvin Meyer [MVP]

DaBartman said:
1) Need to be able to sort short lists of items where it is inconvienent to
create a table abnd have the table sort the items and

You need to tell us how you get your data. You could always put it in a list
box and sort the values there.

2) Anyone have any work
arounds for creating an array of controls on a form? I used to do this with
Visual Basic, but Access will not allow this.

Define your control names sequentially so you can access them with the ()
syntax:

Me("Text" & SomeIndex)

or:

Me.Text & SomeIndex

Then you can:

Dim i As Integer

For i = 1 to 10
Me("txtControlName" & i).Visible = True
Next
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads:
http://www.datastrat.com
http://www.mvps.org/access
 
D

Douglas J. Steele

You can put the items in an array, and use your favourite sort technique on
the array. If you don't have a favourite technique, Randy Birch shows a few
in http://vbnet.mvps.org/code/sort/qscompare.htm (Obligatory warning:
Randy's site is aime at VB programmers. Because there are significant
differences in forms between VB and Access, not all of his code samples port
seamlessly into Access, but you can generally get an idea of what to do from
the VB code itself)

One common approach to simulating control arrays is to use a naming
convention, like txtArgument1, txtArgument2, txtArgument3 and so on. You can
then refer to the individual controls in a loop like:

Dim cltCurr As Control
Dim intLoop As Integer

For intLoop = 1 to 3
Set ctlCurr = Me.Controls("txtArgument" & intLoop)
' do your stuff
Next intLoop

It's not quite as neat for events, though: you'll have to create a generic
function that can rely on ActiveControl, and call that function in the
appropriate event of all of the controls in the pseudoarray.
 
Top