L
Larry R Harrison Jr
I have Access 2000. I am wanting to create a combo box on
a form which shows the CAPTIONS of the table the form is
based on. It's easy to show the field names, but they have
the "field_name" syntax rather than the "Field Name"
syntax, which is why I want it to show the captions
instead of the actual field names. (And I'd like it to
sort by this caption name, which I'm sure would be a tiny
adjustment to the code as it would otherwise be.)
BUT***, and this is imporant--I want its stored value to
be the actual field names.
The reason: this is to be used on a form used by a person
who seems to have a hard time finding the fields on the
form. He can select the field from this combo box and the
form would execute a DoCmd.GoToControl "fieldname" command
in the "After Update" event procedure of the combo box.
The following code was obtained by in a Google newsgroup
archive search:
'*************** Code Start *******************
Function ListCaptions(fld As Control, id As Variant, _
row As Variant, col As Variant, code As Variant) As Variant
Static strCaptions() As String
Static intCount As Integer
Select Case code
Case acLBInitialize ' Initialize.
Dim loDb As Database
Dim loTab As TableDef
Dim lofld As Field
Dim intX As Integer
Set loDb = CurrentDb
'Change the table name here
Set loTab = loDb.TableDefs("NewTable")
intCount = loTab.Fields.Count - 1
ReDim strCaptions(intCount)
On Error Resume Next
For intX = 0 To intCount
strCaptions(intX) = loTab.Fields(intX).Properties _
("Caption")
If Err > 0 Then
strCaptions(intX) = loTab.Fields(intX).Name
Err.Clear
End If
Next
Set loTab = Nothing
Set loDb = Nothing
ListCaptions = True
Case acLBOpen ' Open.
ListCaptions = Timer ' Unique ID.
Case acLBGetRowCount ' Get rows.
ListCaptions = intCount + 1
Case acLBGetColumnCount ' Get columns.
ListCaptions = 1
Case acLBGetColumnWidth ' Get column width.
ListCaptions = -1 ' Use default width.
Case acLBGetValue ' Get the data.
ListCaptions = strCaptions(row)
End Select
End Function
'*************** Code End *********************
I put this code in a module, named it <basListCaptions>
Now trouble is I can't figure out how to call this in the
combo box. I tried entering this in the combo box's "Row
Source":
=ListCaptions(cboGoToField,,1,1,"Caption")
The combo box's name is cboGoToField.
Tips?
LRH
a form which shows the CAPTIONS of the table the form is
based on. It's easy to show the field names, but they have
the "field_name" syntax rather than the "Field Name"
syntax, which is why I want it to show the captions
instead of the actual field names. (And I'd like it to
sort by this caption name, which I'm sure would be a tiny
adjustment to the code as it would otherwise be.)
BUT***, and this is imporant--I want its stored value to
be the actual field names.
The reason: this is to be used on a form used by a person
who seems to have a hard time finding the fields on the
form. He can select the field from this combo box and the
form would execute a DoCmd.GoToControl "fieldname" command
in the "After Update" event procedure of the combo box.
The following code was obtained by in a Google newsgroup
archive search:
'*************** Code Start *******************
Function ListCaptions(fld As Control, id As Variant, _
row As Variant, col As Variant, code As Variant) As Variant
Static strCaptions() As String
Static intCount As Integer
Select Case code
Case acLBInitialize ' Initialize.
Dim loDb As Database
Dim loTab As TableDef
Dim lofld As Field
Dim intX As Integer
Set loDb = CurrentDb
'Change the table name here
Set loTab = loDb.TableDefs("NewTable")
intCount = loTab.Fields.Count - 1
ReDim strCaptions(intCount)
On Error Resume Next
For intX = 0 To intCount
strCaptions(intX) = loTab.Fields(intX).Properties _
("Caption")
If Err > 0 Then
strCaptions(intX) = loTab.Fields(intX).Name
Err.Clear
End If
Next
Set loTab = Nothing
Set loDb = Nothing
ListCaptions = True
Case acLBOpen ' Open.
ListCaptions = Timer ' Unique ID.
Case acLBGetRowCount ' Get rows.
ListCaptions = intCount + 1
Case acLBGetColumnCount ' Get columns.
ListCaptions = 1
Case acLBGetColumnWidth ' Get column width.
ListCaptions = -1 ' Use default width.
Case acLBGetValue ' Get the data.
ListCaptions = strCaptions(row)
End Select
End Function
'*************** Code End *********************
I put this code in a module, named it <basListCaptions>
Now trouble is I can't figure out how to call this in the
combo box. I tried entering this in the combo box's "Row
Source":
=ListCaptions(cboGoToField,,1,1,"Caption")
The combo box's name is cboGoToField.
Tips?
LRH