473,386 Members | 1,753 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

How to make a form not save to a table if left blank?

283 100+
Well i have been playing with this off and on all day and its driving me up a wall.

I have a small form that has 5 text boxes. Now if I were to type nothing in to the pop up box before closeing it nothing is saved to the table on the backend but if i type something and then change my mind and erase it and then just close the form it will save a blank record.

How can i have the form check to see if all of the boxes are blank then erase the info that could have been typed in and then close with out saving?

I was trying to use the OnDirty and AfterUpDate function but was getting no where.
Apr 21 '10 #1
12 1569
TheSmileyCoder
2,322 Expert Mod 2GB
Using afterUpdate is too late (which kinda seems obvious, no offense :O)

In the form's beforeUpdate, have code like this:
Expand|Select|Wrap|Line Numbers
  1. If Me.TextBoxIWantToCheck & ""="" then
  2.   Me.Undo
  3.   Cancel=true
  4. end If
  5.  
You can then expand this to include several criteria if you have more then 1 textbox, and you can add a confirmation dialog if needed.

Edit: remembered this
Another way of doing it without code, is to go to the table design and specify the fields as required. That way you cannot save a record with those fields left blank.
Apr 21 '10 #2
slenish
283 100+
Hi TSO,

I appreciate the help. Well i tried what you said but its still not working. Here is what I have so far.

I have placed this in the form BeforeUpdate function
Expand|Select|Wrap|Line Numbers
  1.  
  2. If Me.Text10 & Text2 & Text4 & Text6 & Text8 = "" Then
  3. Me.Undo
  4. Cancel = True
  5.  
  6. End If
  7.  
What's happening is it wont let me close the form if its left blank but i want it to close still just not save anything. Any ideas?
Thanks again!
Apr 21 '10 #3
NeoPa
32,556 Expert Mod 16PB
Check post #2 again. There's already another idea there waiting.
Apr 22 '10 #4
slenish
283 100+
Hi NeoPa,

I saw the extra part at the bottom where TSO updated his post, but still doesnt help me. I'm trying to make it where none of the fields are required, it just wont save to the table if left blank.

The way its working right now is that it wont save which is good but it also wont close which is not good. I need it to do both, close and not save if the form is left blank.

You got any ideas? I keep trying all kinds of variations. I was trying to set user input to a value so that way if someone typed something in and then erased it it would clear the form before closeing a saving but was having no luck with that either.

This is not exact code just kind of sudo coding my idea

Expand|Select|Wrap|Line Numbers
  1. dim value as string
  2.  
  3. userInput = value
  4. if userInput = value then 
  5. text1 = value
  6.  
  7. else 
  8. if userInput = "" then
  9. value = me.undo
  10. end if
  11.  
is there any way to do Me.Erase?? Me.Undo does not seem to work like it should.

Appreciate the help. good to see you again :)
Apr 22 '10 #5
NeoPa
32,556 Expert Mod 16PB
I saw the extra part at the bottom where TSO updated his post, but still doesnt help me. I'm trying to make it where none of the fields are required, it just wont save to the table if left blank.
Can you explain what you see as the difference between these two situations? I would have thought setting a field or control to required would have just that effect.
Apr 22 '10 #6
slenish
283 100+
Hi NeoPa,

Well the difference is that you are talking about setting a field or control to REQUIRED but that is not what i want.

Maybe you can make a test form and try this to see what the problem is. What I have is a form with 5 text boxes. Now if I leave the boxes blank and dont type anything in the boxes and hit the save record/close form button the form closes and nothing is saved which is great!!

But If i type something in one box and then delete what i typed and then close/save the form(remember the form is now blank because i erased what i typed) the form will now save a blank record which is what I dont want. So its not that i want the form to tell the user you have to type something in here I just want the form to tell the form if the text boxes are left blank go ahead and close just dont save anything.

Its weird that it will close and not save as long as I dont type anything but as soon as I type something, then erase it, then close the form it saves a blank record.

The whole reason behind this is because the form is a pop up form and if the user opens the form on accident and then realizes they dont need it i dont want it to save any blank records that i have to go erase on the table later.

I hope that is a little more detailed explanation.

apprecitate the help :D
Apr 23 '10 #7
robjens
37
You should use the .Value and .Text properties of a TextBox. Value is what's already in the table (as in the field bound to your control) and .Text is what you just typed but not yet stored.
Apr 23 '10 #8
slenish
283 100+
I finally got this to work. Really appreciate all the help everyone.

I had to change TSO orginal answer just a little bit and I had to put it in the Forms OnClose function.

Only thing im trying to get rid of now is a little pop up box that asks if you want to delete the record. Which is fine just wish it would delete it and close with out asking.

Thanks again everyone.

Expand|Select|Wrap|Line Numbers
  1. If Me.Text2 = "" Then
  2. DoCmd.RunCommand acCmdUndo
  3. Cancel = True
  4. End If
Apr 23 '10 #9
NeoPa
32,556 Expert Mod 16PB
Only thing im trying to get rid of now is a little pop up box that asks if you want to delete the record. Which is fine just wish it would delete it and close without asking.
I'm a little confused here. Is this related to the current question (where does deleting come in when updating a record)? Is it possibly a similar, but deletion related, question?
Apr 26 '10 #10
hngtwn
3
I've got exactly the same issue - frustrating. I think I have it beat though. I put a "Done" button on the form that runs this macro:

Criteria / Action / Arguments
/ SetWarnings / No
Forms!MyForm!Text1 Is Null / RunCommand / Undo
/ Close / Form, MyForm, No
/ SetWarnings / Yes


BTW - the SetWarnings action isn't available in the macro builder unless you click "Show all actions" up top. It'll take care of your pop-up.
Apr 26 '10 #11
hngtwn
3
Never mind - sorry. My solution works if you type something into the text box then erase it, but it causes an error if nothing has been entered.
Apr 26 '10 #12
hngtwn
3
One more step - I put an afterupdate event on the text box in question that sets a temporary variable to 1, then added that to the criteria for running the undo command. Finally, I put a RemoveTempVar in the macro that closes the form. Works like a charm.
Apr 26 '10 #13

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

Similar topics

1
by: Paul THompson | last post by:
I am using IE to hide sections of a form. When I display the first section (name='ea'), the form widgets are not clickable in IE nor do they accept focus. When I display the 3rd section...
1
by: meganrobertson22 | last post by:
hi everybody- what is the best way to add data from one form to another? i have 2 tables: person and contract. here are some of the fields. table: person personid (autonumber and primary...
2
by: Paul | last post by:
I've searched this site for a few hours without a solution to my problem. Please help~ In short, the controls on my form have vanished. I can see nothing but a gray screen and grayed out navigator...
6
by: dale zhang | last post by:
Hi, I build a web form with a 4-cell table on the top (flawlayout), followed by some labels and textboxes (gridlayout). The web form is displayed well in dell m60 laptop with all resolution...
27
by: Kim Webb | last post by:
I have a field on a form for project number. I basically want it to be the next available number (ie 06010 then 06011 etc). In the form I create a text box and under control source I put: =!=...
6
by: scottyman | last post by:
I can't make this script work properly. I've gone as far as I can with it and the rest is out of my ability. I can do some html editing but I'm lost in the Java world. The script at the bottom of...
0
by: visionstate | last post by:
Hi there, I have a form which has 2 text boxes, a combo box and a sub form in it (which reads from a query. The query reads from the table). On load, I would like the fields in the text boxes and...
1
by: chris_huh | last post by:
Using the Label Wezard you can easily make labels for all the records in the table, but is there a way to make just one. I have a form that shows the data from a single recordset and on that...
1
imrosie
by: imrosie | last post by:
Hello (from Rosie the newbie), I recently got help with a wonderful event to perform this from 'thescripts'...it recognizes that a name is not in the list an allows for (after parsing first and...
1
by: lupo666 | last post by:
Hi, I have a database with only one table containing the following fields: ID (primary key, auto-counter), Client (Text), Internal_ID (Text), Window (Y/N), Lock(Y/N), LED (Y/N) What I'm...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...

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.