Dont Save OnClose if..

This form has about 12 Text Boxes But when I click cmdClose I dont want the 
record to save if [tbName] Control Source [OwnerLastName] Text Field
This dose not seem to work..........Thanks for any Help.........Bob

Private Sub cmdClose_Click()
  If IsNull(tbName) Then
   If Me.Dirty Then
     Me.Undo
   End If
End If

    DoCmd.Close acForm, Me.Name
End Sub 


0
Bob
1/4/2008 1:32:19 AM
access 16762 articles. 3 followers. Follow

2 Replies
1171 Views

Similar Articles

[PageSpeed] 38

This could be a timing issue, Bob, i.e. the record might already be saved 
before this code runs.

The only way you can be sure to catch this is to use the BeforeUpdate event 
procedure of the *form*. Access fires this event just before the record gets 
saved. You cancel the event if you don't want the record to be saved.

Private Sub Form_BeforeUpdate(Cancel As Integer)
    Dim strMsg As String
    If IsNull(Me.txName) Then
        Cancel = True
        strMsg = "Cannot save while the last name is blank." & vbCrLf & _
            "Correct the entry, or press Esc twice to undo."
        MsgBox strMsg, vbExclamation, "Invalid data"
    End If
End Sub

-- 
Allen Browne - Microsoft MVP.  Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Bob V" <rjvance@ihug.co.nz> wrote in message
news:%239GsWHnTIHA.5208@TK2MSFTNGP04.phx.gbl...
> This form has about 12 Text Boxes But when I click cmdClose I dont want 
> the record to save if [tbName] Control Source [OwnerLastName] Text Field
> This dose not seem to work..........Thanks for any Help.........Bob
>
> Private Sub cmdClose_Click()
>  If IsNull(tbName) Then
>   If Me.Dirty Then
>     Me.Undo
>   End If
> End If
>
>    DoCmd.Close acForm, Me.Name
> End Sub 

0
Allen
1/4/2008 1:50:24 AM
Thanks Allen BRILLIANT worked perfectly...Bob :)

"Allen Browne" <AllenBrowne@SeeSig.Invalid> wrote in message 
news:%23OeHwQnTIHA.5016@TK2MSFTNGP06.phx.gbl...
> This could be a timing issue, Bob, i.e. the record might already be saved 
> before this code runs.
>
> The only way you can be sure to catch this is to use the BeforeUpdate 
> event procedure of the *form*. Access fires this event just before the 
> record gets saved. You cancel the event if you don't want the record to be 
> saved.
>
> Private Sub Form_BeforeUpdate(Cancel As Integer)
>    Dim strMsg As String
>    If IsNull(Me.txName) Then
>        Cancel = True
>        strMsg = "Cannot save while the last name is blank." & vbCrLf & _
>            "Correct the entry, or press Esc twice to undo."
>        MsgBox strMsg, vbExclamation, "Invalid data"
>    End If
> End Sub
>
> -- 
> Allen Browne - Microsoft MVP.  Perth, Western Australia
> Tips for Access users - http://allenbrowne.com/tips.html
> Reply to group, rather than allenbrowne at mvps dot org.
>
> "Bob V" <rjvance@ihug.co.nz> wrote in message
> news:%239GsWHnTIHA.5208@TK2MSFTNGP04.phx.gbl...
>> This form has about 12 Text Boxes But when I click cmdClose I dont want 
>> the record to save if [tbName] Control Source [OwnerLastName] Text Field
>> This dose not seem to work..........Thanks for any Help.........Bob
>>
>> Private Sub cmdClose_Click()
>>  If IsNull(tbName) Then
>>   If Me.Dirty Then
>>     Me.Undo
>>   End If
>> End If
>>
>>    DoCmd.Close acForm, Me.Name
>> End Sub
> 


0
Bob
1/4/2008 9:57:41 PM
Reply:

Similar Artilces:

saving documents
Version: 2008 Operating System: Mac OS X 10.5 (Leopard) Processor: Intel When I go to save a document, my folders do not appear in the "where box". They always did in my older version of Word. How can I save them to the right folder? You have Leopard/Apple to thank for this one :-) Click the square button with the big triangle on it (it's to the right of the Save As:[filename] list) to expand the dialog window. HTH |:>) Bob Jones [MVP] Office:Mac On 8/24/08 3:25 PM, in article 59b57b88.-1@webcrossing.caR9absDaxw, "mary_12@officeformac.com" <mary_12@office...

What format does Publisher save files in?
I'm looking into purchasing Publisher to use in a small business. What formats can I save files in, and can I convert them to .pdf using PDF Create!? njwelch <njwelch@discussions.microsoft.com> was very recently heard to utter: > I'm looking into purchasing Publisher to use in a small business. > What formats can I save files in, and can I convert them to .pdf > using PDF Create!? I don't know about PDF Create! in particular, but Publisher saves files as ..pub. Most programs convert to .pdf not by opening the file with a PDF program, but by printing to a PDF d...

How do I stop my Publisher 2003 document from saving as a webpag.
When I save a particular publication ( a newsletter) in Publisher 2003 as a Publisher 2000 document (so I can work on it elsewhere) it opens as a web page instead of a print document. When I convert it back to print, I lose a few inches of print on the left page that just don't print even when I change the margins. The missing print shows on the screen normally, it is only in print preview and on paper that it cuts off. Can I stop this from happening? Can I retrieve the missing print? Please help! You may have to reconstruct this publication. -- Mary Sauer MSFT MVP http://off...

tooltip
I have an MFC application and although most menu/tool bar icons show the associated Prompt and Tool Tip, there are one or two that just dont show them. I've checked the resources and they look of for all the items (working and non-working) but I cant seem to get all the tool-tips to show up Any help will be much appreciated Phil Tooltips for buttons display only that text which follows \n and corresponds to the prompt for the identical menu item. Do you have a \n in all tooltip text? Just a guess. joe On Mon, 10 Oct 2005 22:20:03 +0100, "Phil Cunningham" <phil@oak...

Save Current email in Directory.
Hi all, Brand brand new to VBA coding. Fully fledgling newbee in the ranks! Hoping for a little help. My final aim is to have a button and a drop-down box in a custom toolbar. The dropdown box will offer a number of local directories and the button will execute a save script which saves the email (with any attachments) in the directory currently selected in the drop-down box. This will ideally work with the email open in the preview pane as opposed to having to double click each message before saving it. I'm sure this is a big job so I'l attack it one section at a ti...

How do you turn off automatic "save a copy" in Excel
I absolutely abhor the fact that excel saves a copy rather than automatically saves to the original document. Does anyone know how to turn off the "save a copy" feature and to have Excel automatically save to the original document. Cecilia, I think you're referring to Autorecover (Tools - Options - Save tab). To automatically save to the original file, use Autosave. It's in Tools - Addins. There are disadvantages to Autosave. Instead, being in the habit of saving at appropriate times is a good technique to master. Consider versions (do Save as, "Myfile-2....

Saving Documents
When I pull up a document to edit, then choose "Save As" to save changed document under a new name, the path does not stay in the same folder. Instead, it pulls up the last folder I saved a document under. For example, I worked on an excel spreadsheet and saved it. I then go to a completely different folder, pull up last week's time sheet, make changes and click "Save As." I want to save it in the same folder, but it pulls up the excel folder I used previously instead. Is there a way to change this setting? "MeredithLeMay" <Meredith...

Saving #4
Can someone please tell me the reason that if you save a 97 version spreadsheet as an (for eg) 2000 version that you cannot open the file on a machine that has Office 97 installed. Please don't worry about being technical. Many thanks Andy If you just save as an xls file you should be able to use of both versions except for any 2000 features not supported on 97. -- Don Guillett SalesAid Software donaldb@281.com "Andy Gee" <anonymous@discussions.microsoft.com> wrote in message news:ea8401c43d0a$0abf4110$a401280a@phx.gbl... > Can someone please tell me the reason tha...

E-mails sent from the CRM browser client are not saved in outlook sent folder
In my implementation of Dynamics CRM 4.0, the e-mails sent from the CRM browser client are not saved in outlook sent folder. How to make to solve this problem ? Thank you in advance Noro On Mar 16, 5:39=A0am, nouredd...@astoine.com wrote: > In my implementation of Dynamics CRM 4.0, the e-mails sent from the > CRM browser client are not saved in outlook sent folder. > > How to make to solve this problem ? > > Thank you in advance > Noro The simplest option is probably to use the Outlook form when sending emails. You can spawn the Outlook form, rather than the CRM one by...

ERRORS WERE DETECTED WHILE SAVING
MS Excel 2007. I open an Excel 2003 workbook in Excel 2007 and then try to save it as an excel 2000-2003 WOrk book and get the following error message. Errors were detected while saving ...fielname... Microsoft office excel may be able to save the file by removing or repairing some features. Anyone any ideas how to solve this problem. If you continue it then saves the file having prompted you to save again and then says that 'No errors were detected. No repairs were necessary" Cheers Dave I would suggest copying all your data to a new file, sheet by sheet. If the file becomes...

Rules dont seem to run auto
I have a problem with RULES running in Outlook 2002. The rules are okay. If I run them manually from the rules wizard they work fine. I have the rules apparently places in the inbox, and I am attempting to MOVE messages that come in to the various email accounts I have folders for. Running them manualy works... they all go where tyeh should. But, the messages just seem to sit there otherwise unless run manually. DavidF. Is it possible that more than one rule is acting on a particular message, and that might be causing the messages to appear not to move? Try adding "stop processing...

can i save one value in a table but print a different value in a .
i want to save a value such as "wnl" in a table but print out a meaning in a report for example " well developed, well nourished in no distress" to decrease the amount of data stored for each patient. Access 2007 One solution is to create a lookup table with an ID field and a text field. Store the long text strings in this table, but only store the ID in the original table. Then use a query to produce the data by linking the two tables. "sheepsrn" wrote: > i want to save a value such as "wnl" in a table but print out a meaning in a > re...

some receive
I have a shaw email account - it works perfectly on my desktop computer with Outlook 2002 - no problems at all. I also access the same email account on my laptop (over a wireless network) with Outlook 2003 & thats where the trouble starts. Using Outlook 2003 i am totally unable to send emails to certain addresses - for instance my fathers email address in england (it is a pop3 email account). However, when he sends emails to me i AM able to receive them in both versions of Outlook. Also, from Outlook 2003 i can send emails to my wife at work, but when she tries to reply she g...

saving documents
if I add pointers to the document class as member variables, how does mfc save the data when I save the document at runtime? I'm worried addresses are saved rather than the actual data. wanwan wrote: > if I add pointers to the document class as member variables, how does > mfc save the data when I save the document at runtime? > > I'm worried addresses are saved rather than the actual data. MFC doesn't save the data (or the pointers). If you use the serialize feature of MFC then the data is saved by code that you must write in the document Serialize function. B...

Saving downloaded statements as a file
I'm using Money 2002 on XP and am downloading bank statements from 2 different banks manually. When I select the download button on the banks web site it takes the statement straignt into Money and applies it to the correct account as it should. But, I want to save the downloaded statement as a file to use in my accounting package. Previously (perhaps with an older version of Money) I could save the OFX(?) file to disk. Why can't I have this option now? In microsoft.public.money, Barry Pyle <Barry Pyle@discussions.microsoft.com> wrote: >I'm using Money 2002 on XP an...

I have saved over a file by mistake
How do I go to a previous save, i.e look at the old file before I saved over it, is there a log/back up somewhere Unless you have a backup, you don't. -- HTH RP "peterdevans" <peterdevans@discussions.microsoft.com> wrote in message news:36F9EBF3-524C-487E-94EF-B02D40ABE3A0@microsoft.com... > How do I go to a previous save, i.e look at the old file before I saved over > it, is there a log/back up somewhere ...

Save As "Word 97-2003 Document" format does not save an RTF file i
Thanks for reviewing this question. Word 2007 does not convert a RTF file to the Word 97 (DOC) format when using Save As and selecting the type: Word 97-2003 Document format. To reproduce: Open Word 2007 add some text to the document Select Save As and the file type "Word 97-2003 & 6.0/95 RTF (*.doc)" Note file is saved in the RTF format Select Save As and set the type to "Word 97-2003 Document (*.doc)" Use the same file name. Notice you will be prompted to save the file again. (This is very annoying to our customers) Open the file in notepad and n...

outlook other than inbox save replies messages with original messages
I have outlook 2002 I hae two personal folder files; one personal one business. All email goes into the personal in box and then gets filtered. When I reply to a message, it goes to the sent folder and not the same folder I replied from. It is turned on in the options. It will work properly in the personal (main) .pst file, but not when the email goes to the business .pst file. ...

Outlook 2003 Saving sent mail
I migrated from Outlook Express 6 to Outlook 2003 two months ago. The installation did fine with importing all my AOL folders from the old program. However I now have a new email account which I set up after the install, and I cannot get my sent items from the new account to save in the Sent Items folder. I have already clicked on Tools, Options, Preferences, Email Options and it is set to save copies of messages in sent items folder. Can you tell me how to get my sent message to save??? Not saving sent messages <Not saving sent messages@discussions.microsoft.com> wrote: &g...

Store start/finish automatically before file save?
I am working on a quite large project, which is to be devided in several logical parts. For each part there is a seperate project-file and where necessary there are cross-project-links between tasks of the different files. At last all seperate sub-project files have a series of important milestones to be monitored in the master project file, where all sub- project files are inserted as linked projects. In the master project file each sub-project milestone is linked to a kind of 'commission milestone', all with a Must Start On of Must Finish On constraint to be referred to....

Saving Custom Toolbars
When I creat a custom toolbar with certain components (e.g. delete, custom flag, etc...) when I close Outlook and reopen its changed (missing components) or sometimes blank. I constantly must reinsert the components manually. Is there a way to save it permanantly or longer? Also can a toolbars be rearranged and saved so it doesn't take up a new line? Thanks Kita ...

Save pictures
Is it possible to save pictures in a Publisher file as a picture file? What version Publisher? You can save as pictures in Publisher 2002 & 03, either by right-clicking, save as picture, or file, save as, scroll down to the image choices. In Publisher 2000 and below it isn't as easy. Group everything you want as a picture, copy and paste into an editing program such as MS Paint. -- Mary Sauer MSFT MVP http://office.microsoft.com/ http://msauer.mvps.org/ news://msnews.microsoft.com http://officebeta.iponet.net/en-us/publisher/FX100649111033.aspx "Mrs. Kasook" <Mrs. K...

e-mail password in not save on exit
Every time I exit Outlook 2002, my password is deleted. I have checked save password each time but it still doesn't save after exiting the program. Anyone know the answer to this one? There have been several issues with passwords not being retained with Outlook. Here are some of the known solutions: For Outlook 2000 or 2002 on Win 98, NT, or 2000: http://support.microsoft.com/default.aspx?scid=kb;en-us;290684 For Outlook 2000 on Windows 2000: (CW) http://support.microsoft.com/default.aspx?scid=kb;en-us;275465 (IMO) http://support.microsoft.com/default.aspx?scid=kb;en-us;259416 F...

Dont miss it !!!
Dear webmaster this is a serious business proposition you should consider carefully. A medical consulting site,(www.arsinoi.com) offers free e-books to your lists of subscribers or members.These e-books will not only offer benefits to your customers, for which they'll be gratefull to YOU, but they'll also appear to be YOURS, because you'll be referred as their sponsor. In addition to that, we'll give you full reselling rights to "hot selling" health , fitness, wellness and wellbeing info-products, provided you just stick our URL to your newsletters or e-mail ...

Word 2004 saving every document as a "read Only" and keeps quitting
Hi, Has anyone had this happen? Word 2004 keeps saving my documents as "read only." I trashed the preferences and reinstalled. Also on every, new or old, document it says "Word can not fire event," along with it quitting for no particular reason. Can you help me figure out why it is saving everything as a read only file? Sigh...I am doing a big project in Word and I am not sure what to do about all these issues. I went to email Microsoft and it says my serial is not the correct one, even thought I am reading it directly off the package. Here is the error report from ...