Open only matching forms

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
 
W

Wayne Morgan

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top