Tuesday, October 02, 2007

Open a form and find a record

The Access buttons wizard includes an option to create a button that Opens a Form and find a record(s) based on a filter. This is fine if you want to filter the form but if you want to find a record and not filter try this code


DoCmd.OpenForm "FX_MyNewForm"
Form_MyNewForm.PrimaryField.SetFocus

DoCmd.FindRecord Me![FieldOnCurrentForm], acEntire

2 comments:

grovelli said...

Hi Garry,
I suppose you meant to type
Form_FX_MyNewForm.PrimaryField.SetFocus.
I'm a bit confused here; since you've set focus to PrimaryField on the newly opened form, then it seems to me Me![FieldOnCurrentForm] refers to a field on the newly opened form, not on the form holding the button or does it?

Garry Robinson said...

FieldOnCurrentForm is correct, that is the value that you are searching for