473,398 Members | 2,404 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,398 software developers and data experts.

When i created my clear button on my form, it is clearing the db, not just the form

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdClear_Click()
  2.  
  3. Me.txtSearchSku = Null
  4. Me.txtNMFCCode = Null
  5. Me.txtSearchDesc = Null
  6.  
  7. Me.Repaint
  8.  
  9. End Sub
  10.  
i have this right now, because if i pick anymore of the fields that are in the database, then it takes those records out of it completely. i need for it just clear the form
Jun 12 '15 #1
12 1517
NeoPa
32,556 Expert Mod 16PB
From your posted code I would guess that you're looking to show an empty record on the form. I also guess that the form you're dealing with is a bound form. IE. It has a Record Source and the controls on the form have Control Sources.

What you need to understand is that bound forms are like a window onto the data behind the form, of the recordset that the form is bound to. If it's pointing to a valid record when you set the control values to Null then that will be passed on to the fields of the record itself.

What you are probably looking for is the idea of moving the form (window) on to a separate record. When you move records in a bound form you see the different data in each of those records. To clear the form what you really need to do is to move to the New record. This is a special record found in all recordsets that allow additions.

Does this sound like it's what you're after?
Jun 13 '15 #2
MikeTheBike
639 Expert 512MB
Hi

Are you trying to cancel all alterations to the form without saving then?

If so, then perhaps Me.Undo (?) or similar, as moving to a new record will save any alterations.

Just a thought.


MTB
Jun 15 '15 #3
I am trying to use the undo but it is not working.

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdClear_Click()
  2. Me!sku.Undo
  3. Me!description.Undo
  4. Me!Hazardous.Undo
  5.  
  6.  
  7. End Sub
i was reading something about adding the beforeupdate, but i am not really sure how that would work. i am new to vba. please help!!
Jun 15 '15 #4
when i click on my clear button after adding the above code, it is not doing anything.
Jun 15 '15 #5
MikeTheBike
639 Expert 512MB
I some time use this
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdCancel_Click()
  2. On Error GoTo Err_cmdCancel_Click
  3.  
  4.     If Me.Dirty Then Me.Undo
  5.  
  6. Exit_cmdCancel_Click:
  7.     Exit Sub
  8.  
  9. Err_cmdCancel_Click:
  10.     MsgBox Err.Description
  11.     Resume Exit_cmdCancel_Click
  12.  
  13. End Sub
If it is not a bound form Me.Dirty will cause an error.

MTB
Jun 15 '15 #6
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdClear_Click()
  2. On Error GoTo err_cmdClear_click
  3. If Me.Dirty Then Me.Undo
  4.  
  5. Exit_cmdClear_click:
  6. err_cmdClear_click:
  7. msgBox: Err.description
  8. Resume Exit_cmdClear_click
  9.  
  10. end sub
this error says invalid use of property and highlights this and goes to the word description. i am so confused right now
Jun 15 '15 #7
i figured it out!! thanks so much!!!
Jun 15 '15 #8
MikeTheBike
639 Expert 512MB
There seem to be two things need correcting ie.

You need an Exit Sub statement after the Exit_cmdClear_click: label otherwise you will never exit the sub!!
You should not have a colon after the msgBox statement

Like this

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdClear_Click()
  2. On Error GoTo err_cmdClear_click
  3.     If Me.Dirty Then Me.Undo
  4.  
  5. Exit_cmdClear_click:
  6.     Exit Sub
  7.  
  8. err_cmdClear_click:
  9.     msgBox Err.description
  10.     Resume Exit_cmdClear_click
  11.  
  12. End Sub
??

MTB
Jun 15 '15 #9
NeoPa
32,556 Expert Mod 16PB
Hi Lilly.

Just a quick note to draw your attention to two warning PMs that you've received. I'm guessing you haven't even noticed that they're there which is the reason you haven't done anything about them yet. If so there is a link at the top of every page that says Inbox(#), where # is the number of PMs sent to you that haven't yet been read.

The PMs are telling you that you must use the [CODE] tags whenever you post code on here so that people can read it in a form that makes sense. Once you have sorted out using the PM system feel free to send one to me asking for assistance using the site if you struggle any time. Some areas are easier than others, and all can be complicated if you're not used to using similar systems anywhere.

@Mike.
Well done for catching this and realising what the question was about.
Jun 15 '15 #10
Yes I just figured it out about the coding part of it. So sorry for the confusion
Jun 15 '15 #11
NeoPa
32,556 Expert Mod 16PB
Don't worry about making honest mistakes. You aren't the first and certainly won't be the last.

No-one here will worry about rules broken in ignorance. Do keep an eye out in case you get any further PMs though. They won't necessarily be about rules of course.
Jun 15 '15 #12
Okay!! Thanks for the advice!!
Jun 15 '15 #13

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

Similar topics

5
by: Matt | last post by:
I want to write a generic clearForm function to clear the form when the user click CLEAR button. Here's my attempts, because I want to take care all html controls. I think I need to test if the...
4
by: karenmiddleol | last post by:
I have a simple form to accept two form fields and display the values entered on pressing the submit button. The following is the form I have created to accept the two entries and display the form...
3
by: Dean Slindee | last post by:
When launching another form from the current form, I use the code below to determine if the form to be launched is already active and showing. If form = Nothing, then I instantiate it, otherwise I...
1
by: Bill_W_Stephens | last post by:
I need a form with two buttons and ability to detect which button was pressed. I got this code to work using a javascript global variable, but I know there must be a better way using DOM. Any...
10
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...
2
by: polocar | last post by:
Hi, suppose that you have a C# form with two buttons, that are the classical "btnOk" and "btnCancel" (besides them, of course in the form there can be many other controls). When the user clicks...
3
by: scripteaze | last post by:
posting to a form with no form name or it's just that i cant find the form name. can anyone explain how to either post to a form with no name or, find the name of the form..here my current output,...
1
by: johnacooke | last post by:
I have a HTML form that is generated in part by PHP. The action attribute on the form tag calls itself, so that I can validate the fields without using any other form of code like Javascript to...
5
by: cazbarr | last post by:
Hi all, I have created a form using a table. I have created a reset form and a send email button. I thought my reset button would clear my form, but this is not happening and I am not sure if...
16
by: Joe Y | last post by:
In my Access program, I have a main form that holds recipe general information and a sub-form that keeps the actual formula. The main form name is “recipe” and Record Source is a table named...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.