Closing forms with VBA

  • Thread starter Thread starter Eliezer
  • Start date Start date
E

Eliezer

I have a database which requires many forms to be opened
and closed quickly, one after another. I used the button
wizard to make buttons to go from one form to another, but
I'm looking for a way to edit the code so that upon
clicking the "go to X" button it closes the form you were
just at. So, say you had the form "stuff bought" open, and
you have a button to go to the form "stuff sold." I would
like code that would modify the existing button code to
close "stuff bought" right after it opens "stuff sold."
Thanks in advance for all help!
 
Private Sub GoToXButton_Click()
DoCmd.OpenForm "Stuff Bought"
DoCmd.Close acForm, Me.Name
End Sub
 
On the line after the DoCmd.OpenForm statement, type in

DoCmd.Close acForm, Me.Name

Hope This Helps
Gerald Stanley MCSD
 
Cool! Thanks!

Why do you need Me.Name? Why isn't it smart enough to
recognize "DoCmd.Close acform, Me" ?
 
Cool! Thanks!

Why do you need Me.Name? Why isn't it smart enough to
recognize "DoCmd.Close acform, Me" ?

Because the Close command requires the *name* of a form as a string for
that argument. Me is a reference to a form object, not the name of that
form.

They "could" have written Close to take a form object instead of a form
name, but most functions is Access/VBA that act upon objects use the name
of the object as a string. In most cases that is easier syntax to work
with.
 
Back
Top