Open only matching forms

  • Thread starter Thread starter Greta
  • Start date Start date
G

Greta

Access 2002...
When an ID number is entered inth Text29, all forms with
that matching ID number open, one ontop of the other. My
problem is that if there is no matching ID in a particular
form, it opens a blank one. Don't want that.
Thanks,
Greta
Here's the code:

Private Sub Text29_AfterUpdate()
DoCmd.OpenForm "1 Form", , , "ID = " & Me!Text29
DoCmd.OpenForm "2 Form", , , "ID = " & Me!Text29
DoCmd.OpenForm "3 Form", , , "ID = " & Me!Text29
DoCmd.OpenForm "4 Form", , , "ID = " & Me!Text29
DoCmd.OpenForm "5 Form", , , "ID = " & Me!Text29
DoCmd.OpenForm "6 Form", , , "ID = " & Me!Text29
DoCmd.OpenForm "7 Form", , , "ID = " & Me!Text29
DoCmd.OpenForm "8 Form", , , "ID = " & Me!Text29
End Sub
 
You will either need to check the record source of the form to see if the value exists
before you try to open the form or you will need to check the RecordCount of the form in
it's Load event and close it or hide it if zero.

The first one will be faster, especially if you have a slow opening form. The second one
may be easier to code.
 
Back
Top