473,895 Members | 2,811 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do I close an open form?

sueb
379 Contributor
I have a little form that I want to:

1. accept a new primary key (chart number) (this is the only field on the form),
2. add a new record with this primary key,
3. open the main form, and
4. close itself

So far, it does 1 through 3, but doesn't do 4, and also gives me an error, saying that there's an operator missing on line 12 of the following code:

Expand|Select|Wrap|Line Numbers
  1. Private Sub ChartNum_Exit(Cancel As Integer)
  2.     Dim stDocName As String
  3.     Dim stMainForm As String
  4.     Dim stLinkCriteria As String
  5.  
  6.     stMainForm = "Patient_IUR_Overview"
  7.     stDocName = "Patients: Add"
  8.  
  9.     DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
  10.     'DoCmd.Close stDocName
  11.  
  12.     stLinkCriteria = "[Patients.Patient Index]=" & Me![Patient Index]
  13.     DoCmd.OpenForm stMainForm, , , stLinkCriteria
  14.  
  15. Exit_ChartNum_Exit:
  16.     Exit Sub
  17.  
  18. Err_ChartNum_Exit:
  19.     MsgBox Err.Description
  20.     Resume Exit_ChartNum_Exit
  21.  
  22. End Sub
  23.  
I'm pretty sure that it has something to do with the index, but I don't know how to fix that line (I cribbed it from another module that behaves similarly).

Thanks in advance, because I know someone will have posted the answer almost before I can come back to check for it!
Jan 13 '11 #1
29 30156
hype261
207 New Member
It looks like you commented out closing the form on line 10. Was this on purpose?
Jan 13 '11 #2
sueb
379 Contributor
I got a "type mismatch" on that line, and I wasn't even sure what this "Close" command was going to attempt to close.
Jan 13 '11 #3
hype261
207 New Member
Here is the MSDN link on the DoCmd.Close method. You got the type mismatch because you are sending a string where it expects an AcObjectType.

http://msdn.microsoft.com/en-us/libr...ffice.12).aspx
Jan 13 '11 #4
sueb
379 Contributor
Thanks for that link, but here is the line I'm using, and it gives me a run-time error of 2585, saying: "This action can't be carried out while processing a form or report event."

Expand|Select|Wrap|Line Numbers
  1. DoCmd.Close acForm, stDocName, acSaveYes
What's wrong with this line?
Jan 13 '11 #5
Rabbit
12,516 Recognized Expert Moderator MVP
Your form is named "Patients: Add"? Bad choice of name. Does "[Patients: Add]" work?
Jan 13 '11 #6
sueb
379 Contributor
So I changed the two lines of code to read:

Expand|Select|Wrap|Line Numbers
  1.     DoCmd.RunCommand acCmdSaveRecord
  2.     DoCmd.Close , stDocName
  3.  
and here's what happens:

1. I add the new chart number, and the correct window opens.
2. I close that window manually, and find that the original "add" window is still there.
3. When I click the window's "X" button, I get: "Syntax error (missing operator) in query expression '[Patients.Patien t Index]='."

How can it be opening the right window if it's having a problem with that particular line? It's actually adding a record for the chart number I entered, and it opens the correct window to look at all the fields for that record, so what's going on? And why does this error only show up when I manually try to close the "add" window?
Jan 14 '11 #7
eneyardi
180 New Member
on deactivate event macro,put type close on action
Jan 14 '11 #8
sueb
379 Contributor
Do what, where, now?
Jan 14 '11 #9
Rabbit
12,516 Recognized Expert Moderator MVP
[Patients.Patien t Index] is the name of the field? If it's not, then that syntax is wrong. Just use [Patient Index] or [Patients].[Patient Index].
Jan 14 '11 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

2
1252
by: Richard Hollenbeck | last post by:
I have buttons to open forms all over the place and they all work. Now I'm trying to open the form at the end of a subroutine in another form but it just stops there. Here's the code: DoCmd.OpenForm "frmEnterGrades" Nothing fancy. Is there something I could be missing? Maybe a property in one of the two forms involved? The form exists and I spelled it correctly.
5
9128
by: Viper | last post by:
.... say, like MS Word opens another instance of himself when you open another document. If you close the first 'Word', the second document remains alive. I can't figure out how to do the same with mySecondForm.Show(); myFirstForm.Close(); // also closes mySecondForm too Thanks. A lot.
2
2915
by: Paul | last post by:
Hi this is related to a previous post, hopefully just a bit clearer description o the problem. I have a parent form that opens a new form (child form) while still leaving the parent form open. Although the child form has a close button (with java script) if the user navigates the parent form to another form the child form is still open. Just wondering if there is a way to close the child form when the user navigates away with the parent...
10
10060
by: morangolds | last post by:
Hi, I've been having a problem with C++ Windows Forms apps not "ending" when you close the form window. I've searched about this problem all over the place and most searches have lead me to believe that this has to do with unreleased form component events or event handlers. I'm comparatively new to .net and windows forms, in the sense that though I've been using them for over 2 years now, it's been rather sporadic. I work with...
1
1709
by: Vai2000 | last post by:
Hi All! We all know how to close a form on a client side (self.close) etc... but does someone know how to close a form on server side (C#) I am opening a pop up window (loading an aspx form) window.open(myform.aspx....) I want to close this form once the user hits submit button on it and capture the value entered in the text box and pass it to a third form (can use session etc...) but someone other trick would be great. TIA
3
10586
by: kev | last post by:
Hi folks, I have a form for registration (frmRegistration) whereby i have two buttons. One is Save which saves record using the OnClick property. I used wizard to create the save button. The other one is Next button which i created to open another form "frmSummary" which displays back the records submitted. (i used the wizard to open form and find specific records to display. All these works superb until a review by users where they...
2
4335
by: Del | last post by:
I have a popup form that consist of a single field called EnteredBy and a Subform that has three fields. The popup form also has a button in the Form Footer called close. In the On Click event I have the following code. DoCmd.Close I want the EnteredBy field to be a required field. So in the On Exit event for that field I have the following code.
6
1951
by: Chandrajit | last post by:
Hi, I am new to vb.net. Please help me in .. I have two form in my application. when i put some data from second from to first form i want to close second form. I am using me.close, but it's not working, the form still remains open. Please help me Thanks in advance.
8
6272
by: Mai Le | last post by:
Hello, I used Microsoft Access to create a login form with Name Password Access Level Admin and User I would like to let Admin login and open MRB form and User login then open other form like "test" Please show me how to do it Thanks in advance I had code below
5
4990
by: =?Utf-8?B?Q2hyaXM=?= | last post by:
I am showing a form by ShowModal(). I put a button on that form. When a user clicks the button a MsgBox will show with question "do you want to close?" yes/no. How to handle the situation: - user clicks "yes" - the form closes - user clicks "no" - nothing happens I have problem with that. It seems that assigning property of button.DialogResult wokrs ok only for the first time (in designer generated code and any longer)
0
9990
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9837
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11250
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10847
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10475
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
8030
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7181
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6072
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3298
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.