T
Tony
Hi Folks
I am using an excellent search form designed by Dev Ashish & Terry Kreft and downloaded from the MS Access Web (http://www.mvps.org/access/resources/downloads.htm). There is one addition that I would like - that is - the form uses VBA to dynamically displays fields in a combo box but always in random order. Can someone suggest a method for displaying the fields in correct alphabetical order - this would be very useful
For information, I have looked at the code behind the form and these 2 routines are used to populate the rowsource of the combo boxes
Any help would be appreciated. Thank you
Ton
'VBA Code ---------------------------------------
Function fListFill(ctl As Control, varID As Variant, lngRow As Long,
lngCol As Long, intCode As Integer) As Varian
'The callback function for the first comb
' sFillCombo takes care of the rest of 'em
On Error GoTo ErrHandle
Static sastrObjSource() As Strin
Static sastrFields() As Strin
Static slngCount As Lon
Static sdb As Databas
Dim i As Lon
Dim j As Lon
Dim tdf As TableDe
Dim rsQdf As Recordse
Dim fld As Fiel
Dim varRet As Varian
Dim strObjectType As Strin
Dim varItem As Varian
Select Case intCod
Case acLBInitializ
If sdb Is Nothing Then Set sdb = CurrentD
With M
ReDim sastrObjSource(0
'Are we looking for a table or a quer
sastrObjSource(0) = .lstTables.Column(0
strObjectType = .lstTables.Column(1
j = -
If strObjectType = "Table" The
Set tdf = sdb.TableDefs(sastrObjSource(0)
Me.lstTables.Tag = tdf.Fields.Coun
'Get a list of all the field
For Each fld In tdf.Field
j = j +
ReDim Preserve sastrFields(j
sastrFields(j) = fld.Nam
Nex
j = UBound(sastrFields
Els
'Since the fieldnames can be changed, safest way is t
'open a recordset and go through it's Fields collectio
Set rsQdf = sdb.OpenRecordset(
"Select * from [" & sastrObjSource(0) & "] Where 1=2",
dbOpenSnapshot
Me.lstTables.Tag = rsQdf.Fields.Coun
For Each fld In rsQdf.Field
j = j +
ReDim Preserve sastrFields(j
sastrFields(j) = fld.Nam
Nex
j = UBound(sastrFields
End I
'sort the strin
Call apiSortStringArray(sastrFields
slngCount = UBound(sastrFields) +
'create a module level variant array for other combo
mvarOriginalFields = sastrField
End Wit
varRet = Tru
Case acLBOpe
varRet = Time
Case acLBGetRowCoun
varRet = slngCoun
Case acLBGetValu
varRet = sastrFields(lngRow
Case acLBEn
Set rsQdf = Nothin
Set tdf = Nothin
Set sdb = Nothin
Erase sastrField
Erase sastrObjSourc
End Selec
fListFill = varRe
ExitHere
Exit Functio
ErrHandler
Resume ExitHer
End Functio
Private Sub sFillCombo(intTargetIndex As Integer
'Fills the Rowsource for a comb
On Error GoTo ErrHandle
Dim i As Lon
Dim j As Intege
Dim strOut As Strin
Dim ctlTarget As Contro
'Which one to fill
Set ctlTarget = Me("cbxFld" & intTargetIndex
For i = LBound(mvarOriginalFields) To UBound(mvarOriginalFields
strOut = strOut & mvarOriginalFields(i) & ";
Nex
With ctlTarge
.RowSourceType = "Value List
.RowSource = strOu
End Wit
ExitHere
Set ctlTarget = Nothin
Exit Su
ErrHandler
Resume ExitHer
End Su
I am using an excellent search form designed by Dev Ashish & Terry Kreft and downloaded from the MS Access Web (http://www.mvps.org/access/resources/downloads.htm). There is one addition that I would like - that is - the form uses VBA to dynamically displays fields in a combo box but always in random order. Can someone suggest a method for displaying the fields in correct alphabetical order - this would be very useful
For information, I have looked at the code behind the form and these 2 routines are used to populate the rowsource of the combo boxes
Any help would be appreciated. Thank you
Ton
'VBA Code ---------------------------------------
Function fListFill(ctl As Control, varID As Variant, lngRow As Long,
lngCol As Long, intCode As Integer) As Varian
'The callback function for the first comb
' sFillCombo takes care of the rest of 'em
On Error GoTo ErrHandle
Static sastrObjSource() As Strin
Static sastrFields() As Strin
Static slngCount As Lon
Static sdb As Databas
Dim i As Lon
Dim j As Lon
Dim tdf As TableDe
Dim rsQdf As Recordse
Dim fld As Fiel
Dim varRet As Varian
Dim strObjectType As Strin
Dim varItem As Varian
Select Case intCod
Case acLBInitializ
If sdb Is Nothing Then Set sdb = CurrentD
With M
ReDim sastrObjSource(0
'Are we looking for a table or a quer
sastrObjSource(0) = .lstTables.Column(0
strObjectType = .lstTables.Column(1
j = -
If strObjectType = "Table" The
Set tdf = sdb.TableDefs(sastrObjSource(0)
Me.lstTables.Tag = tdf.Fields.Coun
'Get a list of all the field
For Each fld In tdf.Field
j = j +
ReDim Preserve sastrFields(j
sastrFields(j) = fld.Nam
Nex
j = UBound(sastrFields
Els
'Since the fieldnames can be changed, safest way is t
'open a recordset and go through it's Fields collectio
Set rsQdf = sdb.OpenRecordset(
"Select * from [" & sastrObjSource(0) & "] Where 1=2",
dbOpenSnapshot
Me.lstTables.Tag = rsQdf.Fields.Coun
For Each fld In rsQdf.Field
j = j +
ReDim Preserve sastrFields(j
sastrFields(j) = fld.Nam
Nex
j = UBound(sastrFields
End I
'sort the strin
Call apiSortStringArray(sastrFields
slngCount = UBound(sastrFields) +
'create a module level variant array for other combo
mvarOriginalFields = sastrField
End Wit
varRet = Tru
Case acLBOpe
varRet = Time
Case acLBGetRowCoun
varRet = slngCoun
Case acLBGetValu
varRet = sastrFields(lngRow
Case acLBEn
Set rsQdf = Nothin
Set tdf = Nothin
Set sdb = Nothin
Erase sastrField
Erase sastrObjSourc
End Selec
fListFill = varRe
ExitHere
Exit Functio
ErrHandler
Resume ExitHer
End Functio
Private Sub sFillCombo(intTargetIndex As Integer
'Fills the Rowsource for a comb
On Error GoTo ErrHandle
Dim i As Lon
Dim j As Intege
Dim strOut As Strin
Dim ctlTarget As Contro
'Which one to fill
Set ctlTarget = Me("cbxFld" & intTargetIndex
For i = LBound(mvarOriginalFields) To UBound(mvarOriginalFields
strOut = strOut & mvarOriginalFields(i) & ";
Nex
With ctlTarge
.RowSourceType = "Value List
.RowSource = strOu
End Wit
ExitHere
Set ctlTarget = Nothin
Exit Su
ErrHandler
Resume ExitHer
End Su