ACC: Four Ways to Move to a Record from a Combo Box SelectionID: Q100132
|
Moderate: Requires basic macro, coding, and interoperability skills.
This article lists four different methods of moving to a specific record
based on a combo box selection.
Method 1: In the AfterUpdate property of the combo box, call a macro
using the FindRecord action.
Method 2: In the AfterUpdate property of the combo box, call a macro
using the ApplyFilter action.
Method 3: Use a Form/Subform, with the combo box in the main form and
the data in the subform, bound by the LinkMasterFields and
LinkChildFields properties.
Method 4: Base the form on a query that joins two tables and bind the
combo box to the field that controls the join, using the
AutoLookup technique.
The following table compares the features (benefits and drawbacks) of
the four methods:
Method Number: 1 2 3 4
---------------------------------------------
Requires no code/macros x x
Saves on subforms x x x
Can scroll to other records x x x
Does not require a query x x x
Can edit records x x x
Sub ComboNN_AfterUpdate()
'Find the record that matches the control.
Me.RecordsetClone.Findfirst "[ProductID] = " & Me![ComboNN]
Me.Bookmark = Me.RecordSetClone.Bookmark
End Sub
Text Box
------------------------
ControlName: ProductID
ControlSource: ProductID
Visible: Yes
Combo Box
------------------------------
ControlName: cboLookup
ControlSource: <leave blank>
RowSourceType: Table/Query
RowSource: Products
ColumnCount: 4
ColumnWidths: 0";2"
BoundColumn: 1
After Update: mcrLocateProduct
Macro Name Action
-----------------------------
mcrLocateProduct GoToControl
FindRecord
mcrLocateProduct Actions
---------------------------
GoToControl
ControlName: [ProductID]
FindRecord
Find What: =cboLookup
Find First: Yes
Combo Box
----------------------------------------------
ControlName: cboLookup
ControlSource: <leave blank>
RowSourceType: Table/Query
RowSource: Select [ProductName] from Products;
BoundColumn: 1
ColumnWidths: 1"
AfterUpdate: mcrLocateProduct
Macro Name Action
----------------------------
mcrLocateProduct SetValue
Requery
mcrLocateProduct Actions
--------------------------------------
SetValue
Item: Forms![frmComboTest].FilterOn
Expression: True
Macro Name Action
-------------------------------
mcrLocateProduct ApplyFilter
mcrLocateProduct Actions
-----------------------------------------------------
ApplyFilter
Where:[ProductID]=Forms![frmComboTest]![cboLookup]
Combo Box
----------------------------
ControlName: cboLookup
ControlSource: <leave blank>
RowSourceType: Table/Query
RowSource: Products
ColumnCount: 4
ColumnWidths: 0";2"
BoundColumn: 1
Text Box
------------------------
ControlName: ProductID
ControlSource: ProductID
Visible: Yes
Subform
----------------------------
LinkChildFields: [ProductID]
LinkMasterFields: cboLookup
Query: qryProductSelect
-----------------------------------------------
Field: ProductID
Table Name: tblProductSelect
Show: X (checked on)
Field: <any other fields you are interested in>
TableName: Products
Combo Box
--------------------------
ControlName: ProductID
ControlSource: ProductID
RowSourceType: Table/Query
RowSource: Products
ColumnCount: 1
ColumnWidths: 2"
BoundColumn: 1
For more information about AutoLookup queries, type "AutoLookup" in the
Office Assistant, click Search, and then click to view "About AutoLookup
queries that enter data automatically."
For more information about referencing controls on a form, type
"Identifiers" in the Office Assistant, click Search, and then click to view
"Use values in expresions."
For more information about using the Control Wizard, type "control wizard
find record" in the Office Assistant, click Search, and then click to view
"Find a record by selecting a value from a list."
For more information on how to use the Filter By Form technique, type
"Filter By Form" in the Office Assistant, click Search, and then click to
view "Create a Filter in a Table, Query, or Form."
Additional query words: Auto lookup forms text box move
Keywords : kbusage FmsCmbo
Version : WINDOWS:1.0,1.1,2.0,7.0,97
Platform : WINDOWS
Issue type : kbhowto
Last Reviewed: March 26, 1999