I 'borrowed' a bit of code from the standard Contacts template DB to try and make a combo box open a record. In the template DB it's done in Macro, so I converted it to VBA to copy over - which produced this:
Code:
Private Sub cboGoToContact_AfterUpdate()On Error GoTo cboGoToContact_AfterUpdate_Err
If (IsNull(Screen.ActiveControl)) Then
Exit Sub
End If
On Error Resume Next
If (Form.Dirty) Then
DoCmd.RunCommand acCmdSaveRecord
End If
If (MacroError.Number <> 0) Then
Beep
MsgBox MacroError.Description, vbOKOnly, ""
Exit Sub
End If
On Error GoTo 0
TempVars.Add "ActiveControlValue", "[Screen].[ActiveControl]"
If (CurrentProject.IsTrusted) Then
Screen.ActiveControl = Null
End If
If (Form.FilterOn) Then
DoCmd.RunCommand acCmdRemoveFilterSort
End If
DoCmd.SearchForRecord , "", acFirst, "[ID]=" & TempVars!Activecontrolvalue
TempVars.Remove "ActiveControlValue"
cboGoToContact_AfterUpdate_Exit:
Exit Sub
cboGoToContact_AfterUpdate_Err:
MsgBox Error$
Resume cboGoToContact_AfterUpdate_Exit
End Sub
EDITED...
Which doesn't work I've tried it with 3 records in the database, call them A B and C
If you open the form on record 'A' and then choose 'B' in the combo box, it shows record 'C'. If you open record 'B' in the combo box, then choose record 'A' in the combo box, it shows Record 'C'. If you choose record 'A' or 'B' in the combo box, it shows... erm... record 'C'.
Any ideas?