Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Close a form

Status
Not open for further replies.

Whitebat

Technical User
Jun 19, 2001
47
DE
hi i have a form that i want to close in vba. but it seems like the close and quit and from.exit /close dont work so any ideas on how to close a form ? oh by the way unload is not working either same to hide

Thanks Whitebat
 
Using:
Code:
UserForm1.Show
UserForm1.Hide
OR
Code:
Me.Hide
work fine for me.

If this still fails then please give more details about how you open the form and how you are trying to close it (i.e. I presume you are trying to close using a button click event)

Hope this helps

Clive [infinity]
Ex nihilo, nihil fit (Out of nothing, nothing comes)
 
well no it doesnt work. I always get the error message Method or data member not found. I know it is working in VB but it seems like its not in VBA. Well anyways i found a solution for me i just dont let my users get that far and than i dont have the need of closing a form anymore.
but thanks for your reply

Thanks Whitebat
 
I tried that and vba does know unload because it is correcting it to upper case ( only first letter) but it stays black instead of turning blue. And when i let it run it doesnt do anything no error message no nothing

Thanks Whitebat
 
Hmmm ... despite the fact that you say you've solved this problem, I can't help picking over this one.

Code:
Unload Me
should definitely work.

"Black instead of blue" - I think you must've been playing around with the editor formats.
Code:
Unload
doesn't show up as a keyword when I type it in, but it does work, ie it does remove the form from the memory.

Assuming that it's not a "simple" error ie you've mispelt the form name, I can only think that's there's something that's going on in the background that's negating the Unload Me command. Maybe the code that follows it is firing another event that sets off a chain reaction whereby your form is loaded again. Perhaps you'd need to set application.enableevents to false.

In any event, unload me does work, I can assure you. Since it's being unpredictable here I think it may be worth digging around (ie stepping through your code) to see why this is happening as your program is not working as it should. Personally, I never like that happening to me!

 
alrighty now with stepping through my code with a turned off error handler (gee) i get the following error message run time error 361 cant load or unload this object. but have no clue why i read through the help but none of the possibilities of causing the error seem to fit.

Thanks Whitebat
 
Well, I'm going to have to hold my hands up and say I can't help you mate.

I've tried googling with "error 361" but I very much doubt I'm getting any more info than you are.

Other than a cider goblin having put a curse on your PC, I'm stumped. Sorry.

 
Hi Whitebat

I created a userform in Excel, named it TestUserForm, added a commandbutton, named it cmdClose, and added this code to the OnClick action:

Code:
Private Sub cmdClose_Click()
    Unload Me
End Sub

Works a treat.

Try this out & see if it works - if all else fails, can you recreate the Userform & copy your current userform code accross?

Also, which MS app are you using the form in? Might shed some light ...

BTW - I also tested using
Code:
Me.Hide
and that works fine as well. Only reason for not using it is that the form stays memory resident as opposed
to Unload which kills it completely

HTH




Cheers
Nikki
[bat] Look, mommy, I'm flying!
 
lol good thing that i solved it already right ? :) thanks for your help anyways. And now i can go to my boss and tell him that i have a curse on my machine and thats why he needs to sent me in my easter holidays right away :). lol.
I wish you a nice weekend and a happy easter

Thanks Whitebat
 
Well i am usinf vba for access and here it just aint. but thanks :)

Thanks Whitebat
 
aha!
in that case use
Code:
DoCmd.Close

HTH

Cheers
Nikki
[bat] Look, mommy, I'm flying!
 
true and not true
this way i figured its working DoCmd.Close , , acSaveNo
but its not working if i say DoCmd.Close acForm, FormName, acSaveNo
when i do that i get the error runtime 2948 ( wrong data types) isnt that weird ??


oh well

Thanks Whitebat
 
weird indeed. I copied your code (DoCmd.Close acForm, FormName, acSaveNo) into my testform, made no changes, & it works

Using Access97

sheesh - have to put it down to a typical MS "feature"
you know the kind - it keeps you busy for 3 days before you just give up & program around it ...

Perhaps if you posted in the Access forms forum someone's got an answer for you

Good luck


Cheers
Nikki
[bat] Look, mommy, I'm flying!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top