|
-
Aug 20th, 2003, 07:28 AM
#1
Thread Starter
New Member
Docmd.close
Using DoCmd.Close to close a form other than the active form does not work e.g.
Active form: frmUserForm1
Form to be closed: frmUserForm2
Code: DoCmd.Close, acForm,"frmUserForm2"
Unfortunately, frmUserForm2 just sits there looking at me. Why will it not close?
-
Aug 20th, 2003, 11:35 AM
#2
New Member
The only thing that I could see that may cause the command to fail is the comma (,) right after the DoCmd.Close...
VB Code:
DoCmd.Close[COLOR=red],[/COLOR] acForm,"frmUserForm2"
Try it this way and see what happens:
VB Code:
DoCmd.Close acForm, "frmUserForm2"
Hope this helps!
-
Aug 21st, 2003, 02:12 AM
#3
Thread Starter
New Member
Thanks for that draybu. Unfortunately, the way you have suggested is actually the way I have the code written; I made a mistake when typing the code into my post. So, the code you have suggested doesn't work for me. Any other ideas anyone....please!!!!
-
Aug 21st, 2003, 08:01 AM
#4
Addicted Member
I'll sort it...
VB Code:
For Each frm In Forms
If frm.name <> "frmUserForm1"
Then
DoCmd.Close acForm, frm.name
End If
Next frm
or
VB Code:
For Each frm In Forms
If frm.name = "frmUserForm2"
Then
DoCmd.Close acForm, frm.name
End If
Next frm
-
Aug 25th, 2003, 05:11 PM
#5
Addicted Member
Try
formname1.hide
this hides the forms and make them load faster when you use them again
-
Aug 27th, 2003, 03:37 AM
#6
Addicted Member
If you hide forms with data in them which is meant to go into a database, it won't enter UNTIL the form is closed, meaning if you need the data on another form, you're screwed. Also hiding forms means they still use memory, leading to slower performance.
Stick with closing them.
-
Aug 28th, 2003, 04:36 AM
#7
Fanatic Member
A common cause of form fails to close is mis-spelled form names... for me at any rate.
VB Code:
Public Function closeform(NameOfForm, OpenThisForm As Variant)
'This function closes the current form and loads another
'You can define "code" words and add specialist actions in the case select
'other than that the Form named to be opened (if it is a real form name)
'will result in that form opened.
Dim CF_Result As Boolean
CF_Result = False
On Error GoTo Err
Select Case OpenThisForm 'select the open via nickname
Case "CJE"
DoCmd.OpenForm "Plus Clients and estimates"
If NameOfForm <> "Plus Clients and estimates" Then CF_Result = True
Case "Y" 'Add popups
DoCmd.OpenForm "Start-Up"
Case "CAL" 'Add other one off special actions
DoCmd.OpenReport "Calender01"
Case Else 'select to open via true name (better)
If NameOfForm <> OpenThisForm Then
DoCmd.OpenForm OpenThisForm
CF_Result = True
Else
CF_Result = False
End If
End Select
GoTo No_Error 'skip this old fasioned "goto" jumping
err2:
CF_Result = False
MsgBox "Error SB42.1: form can not be closed. " & Err.Number & " - " & Err.Description
GoTo Still_no_error 'get out of this and end the function
Err:
MsgBox "Failed to find " & OpenThisForm
CF_Result = False
No_Error:
On Error GoTo err2
If CF_Result <> False Then DoCmd.Close acForm, NameOfForm
Still_no_error:
closeform = CF_Result
End Function
Recently I developed a block of code for dealing with the old chestnut of close me and open him in the world of form control. This is quite well tested and I hope might help.
Feel free to use the code (The case select allows you to set up nick-names for long winded form names).
Another thought is: what is you non-closing form doing? By that I mean when you try to close it is it being opened still and are you getting any error messages? if you've used on error resume next then REM it out and read the error reports.
Are you useing many ActiveX componants on the forms?
If I think of any other causes I'll post them here as well.
Last edited by Matt_T_hat; Sep 18th, 2003 at 04:02 AM.
-
Aug 28th, 2003, 04:41 AM
#8
Addicted Member
Bloody hell Mat. That's some extreme code for closing a form....
Impressive, but a little overkill don't you think?
:S
I had the same problem in Access VBA I found closing a form from another using docmd.close impossible, hence the code I wrote earlier.......
If anyone can get the docmd.close command to work JUST on it's on, I'd be impressed....
then again, I'm impressed at juggling.
-
Sep 15th, 2003, 03:56 PM
#9
Hyperactive Member
I have no problem with this.. I just created two forms.. form5 and form6.. the command button on 5 closes 6 with a click.. there was no problem..
VB Code:
Private Sub Command0_Click()
DoCmd.Close acForm, "form6"
End Sub
-
Sep 15th, 2003, 05:43 PM
#10
New Member
I really don't know what the problem is
I tried it my self and it works with this code
DoCmd.Close acForm, "frmUserform2"
If you make a button and you make those 2 forms it just has 2 work.
-
Sep 16th, 2003, 03:15 AM
#11
Addicted Member
maybe you're using a different VBA version, cause it sure as hell doesnt work here.
-
Sep 16th, 2003, 07:57 AM
#12
Hyperactive Member
-
Sep 16th, 2003, 10:57 AM
#13
New Member
-
Sep 17th, 2003, 05:46 AM
#14
Addicted Member
I'm using 2k.
It's just a bug, like how you can't select .text in your code and you have to use .value
Or is that 2k only too....
-
Sep 18th, 2003, 03:59 AM
#15
Fanatic Member
Originally posted by Bazzlad
I'm using 2k.
It's just a bug, like how you can't select .text in your code and you have to use .value
Or is that 2k only too....
So is this thread resolved? Is that the final answer? Sorry it's a bug... does MacroSoft not have the umption to release a fix?... Or does anyone know of a patch activeX or otherwise? Or perhaps there is a definitive way to do it? I know my "overkill" code does the job and can cope with seriouse abuse without crashing anything. Perhaps we need to work on a fairly deffinitive solution.
One day some newbie is going to search VBforums.com and find this thread only to go away without an answer to post the question again and again...
I think we should perhaps put our heads togeather and find a set of answers.
-
Sep 18th, 2003, 04:08 AM
#16
Fanatic Member
Originally posted by Bazzlad
Bloody hell Mat. That's some extreme code for closing a form....
Impressive, but a little overkill don't you think?
:S
I had the same problem in Access VBA I found closing a form from another using docmd.close impossible, hence the code I wrote earlier.......
If anyone can get the docmd.close command to work JUST on it's on, I'd be impressed....
then again, I'm impressed at juggling.
For the record the code given sits in a module to be called by code when needed. I wrote it for openiong and closeing forms in access 2000 as I got fed up with getting the docmd.open and the docmd.close in the wrong order. Plus this gives less "ficker" as the form that is closed is closed whent the other form is covering it. The result was a happy pro looking transition.
Over kill - maybe, usefull - for sure!
perhaps a stripped down version of the code posted would be the answer. What do you think?
-
Sep 18th, 2003, 04:52 AM
#17
Addicted Member
In fairness I very much like your code, it's well written and smart, the over kill comment was made because it appears we have to write a page of code to replace this:
"Docmd.close"
Lol.
I think between our two solutions no1 should have a problem....
there are two ways of shutting down a form here, so it's got to be solved hasn't it?
Cheers
-
Sep 19th, 2003, 05:01 AM
#18
Fanatic Member
Originally posted by Bazzlad
I think between our two solutions no1 should have a problem....
there are two ways of shutting down a form here, so it's got to be solved hasn't it?
I think perhaps you could be right.
-
Sep 22nd, 2003, 05:17 PM
#19
Lively Member
Originally posted by Bazzlad
If you hide forms with data in them which is meant to go into a database, it won't enter UNTIL the form is closed, meaning if you need the data on another form, you're screwed.
You could use the access command constant (SaveRecord) to remedy this situation.
Code:
DoCmd.RunCommand acCmdSaveRecord
Best to check if the Form is Dirty first otherwise there's no point in running it.
Code:
If Me.Dirty Then DoCmd.RunCommand acCmdSaveRecord
As for the rest of the problem.
Have you compacted and repaired the database on the chance it may just be one of Access's niggles?
Have you exported all objects into a new database?
The only other thing I can think of is if there is any condition in the Form's Unload event whereby you are setting Cancel to True.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|