Closing forms


M

Mark A. Sam

I want to close the open forms by enumerating through the forms collection,
but don't know the syntax to close the form from the variable name, frm.

I tried,

Docmd.Close acForm, frm.name

which gave me an error saying it didn't recognize the control "form name"

Where "form name" is the actualy form name.

Thanks

Mark A.Sam
 
Ad

Advertisements

D

Douglas J. Steele

Are you trying to use For Each frm In Forms? That doesn't work: you need to
go backwards through the collection, not forwards.

The following untested aircode should do it:

Dim lngLoop As Long

For lngLoop = (Forms.Count - 1) To 1 Step -1
DoCmd.Close acForm, Forms(lngLoop).Name
Next lngLoop
 
D

Douglas J. Steele

I'm unsure if you're agreeing with me that going forward through the
collection doesn't work, or that the aircode I posted doesn't work.
 
M

Mark A. Sam

Doug,

Sorry for the confusion. Your method worked fine. The For Each method,
would only close on form.

I wrote a logon system for my client and this is to close all form and
disable the buttons if the user logs off from the switchboard. It does
exactly what I want.

Thanks.

Mark
 
D

Douglas J. Steele

What happens if you enumerate using For Each is that the pointer is put at
the first form. When you delete that form, the pointer has to be put
somewhere else, so it moves to what was the second form. When you go to the
Next statement, the pointer moves to the next form, which is what was the
third form. If there wasn't a third form, it'll stop, having only deleted
the first form. If there are multiple forms, it'll end up deleting every
other one.
 
Ad

Advertisements


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