423,103 Members | 1,347 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 423,103 IT Pros & Developers. It's quick & easy.

Creating a reset/clear button for a form

P: 17
Good Afternoon,

I have been trying to figure this out for days. I have a search form in Access 2007 that is unbound with unbound text boxes. The submit button works great, but I am trying to creat a clear button so that the user can clear out their information at once instead of each individual field. My form name is SearchingForm and the text boxes are clientname, operatingstate, product. I have tried the following codes:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub resetbtn_Click()
  3.  
  4. Me.Refresh
  5.  
  6. End Sub
  7.  
  8.  
also tried

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub resetbtn_Click()
  3.  
  4. Me.clientname = ""
  5. Me.operatingstate = ""
  6. Me.product = ""
  7. Me.Refresh
  8.  
  9. End Sub
  10.  
  11.  
Any help would be appreciated. I have not used Access or VB in years, so I am trying to relearn for work. Thanks
May 6 '14 #1

✓ answered by Seth Schrock

Try going to Access Options>Trust Center>Trust Center Settings>Message Bar. Make sure that the option to Show the Message Bar in all applications when active content... has been blocked is selected. Then close the database and open it again. See if you get a yellow bar telling you that some content could be harmful and was disabled. If it does, click enable content and then try your button.

Share this Question
Share on Google+
28 Replies


Seth Schrock
Expert 2.5K+
P: 2,886
The refresh isn't needed. What happens with your second block of code? Do you get an error message or does it run and just not clear the fields?
May 6 '14 #2

P: 17
Thank you for the quick response. On either block of code that I try it does nothing, just sits there. I have also tried the = Null instead of the = "". Just to clarify on the code that I listed it was not in there at the same time, that is code that I tried on two different attempts at trying to get it to work
May 6 '14 #3

100+
P: 296
So, your textboxes are named: clientname, operatingstate, and product?
May 6 '14 #4

P: 17
Sorry for the delay. Yes the three text boxes are named the above. (no capitalization and no spaces).
May 6 '14 #5

100+
P: 296
Have you tried:
Expand|Select|Wrap|Line Numbers
  1. Me.buttonName.Value = ""
May 7 '14 #6

P: 17
Yes, I have tried that as well and had the same response - nothing happened.
May 7 '14 #7

Seth Schrock
Expert 2.5K+
P: 2,886
This makes me think that your code isn't running. Try typing STOP right before your code and then click your Clear button and see if the code stops at that line.
May 7 '14 #8

P: 17
Ok I just tried that, but I am not sure what it is suppose to do. I get the same result. I have the code open when I am clicking on the clear button and I see nothing happening. Thanks so much for all of the help with this. Here is the code that I have put in

Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. Private Sub resetbtn_Click()
  4.  
  5. Stop
  6.  
  7. Me.clientname = ""
  8. Me.operatingstate = ""
  9. Me.product = ""
  10.  
  11. End Sub
  12.  
  13.  
May 7 '14 #9

Seth Schrock
Expert 2.5K+
P: 2,886
Ok, if the code was actually running, then the code would have stopped with your Stop line highlighted. Go to your Reset button's event list in the properties window. Click in the On Click event line and then click the ellipsis button. If it is attached to your code, it will take you to it. If not, then it will either take you to the code window and create a new event sub or it will ask you what you want to create. If the later, then choose the code option and click OK. That will then create a new event sub and then you can put your code in that one and delete your old one.
May 7 '14 #10

P: 17
I did that and it took me to my code.
May 7 '14 #11

Expert 100+
P: 1,219
So it sounds like you wrote the code where it should have been, named as it should have been, but did not wire it up to the event. Now that you've done that, I suspect your click will work.

Jim
May 7 '14 #12

P: 17
You would think that would be the case, but it is still not working. I am not sure what I am doing incorrectly - but for some reason it is still not working.
May 7 '14 #13

zmbd
Expert Mod 5K+
P: 5,202
OP:2ndBlock:line7:Me.Refresh

change to

OP:2ndBlock:line7:Me.Repaint

post back results if any.
May 7 '14 #14

Seth Schrock
Expert 2.5K+
P: 2,886
Try going to Access Options>Trust Center>Trust Center Settings>Message Bar. Make sure that the option to Show the Message Bar in all applications when active content... has been blocked is selected. Then close the database and open it again. See if you get a yellow bar telling you that some content could be harmful and was disabled. If it does, click enable content and then try your button.
May 7 '14 #15

P: 17
Seth - I checked and that option is selected in the trust center

Zmbd - Do you want me to just put Me.Repaint and leave out the specific textboxes?
May 7 '14 #16

Seth Schrock
Expert 2.5K+
P: 2,886
Did you close and then reopen your database?
May 7 '14 #17

P: 17
Zmbd - I tried Me.Repaint with the textboxes listed and without and nothing. It is like it isn't even going to the code. Here are the three codes that I tried at 3 seperate times.

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub resetbtn_Click()
  3.  
  4. Me.clientname = Null
  5. Me.operatingstate = Null
  6. Me.product = Null
  7. Me.Repaint
  8.  
  9. End Sub
  10.  
  11.  
Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub resetbtn_Click()
  3.  
  4. Me.clientname = ""
  5. Me.operatingstate = ""
  6. Me.product = ""
  7. Me.Repaint
  8.  
  9. End Sub
  10.  
Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub resetbtn_Click()
  3.  
  4. Me.Repaint
  5.  
  6. End Sub
  7.  
I am at a loss as to what I am doing incorrectly.
May 7 '14 #18

P: 17
Seth - that was the setting in the trust center when I went in there, I didn't have to change anything
May 7 '14 #19

Seth Schrock
Expert 2.5K+
P: 2,886
I realize that. But you still need to close and reopen the database to then get the message to popup. Most people just hit the X when they see the message and don't even think of it. Once closed, it won't pop up until you close and reopen the database, hence why I'm recommending that you try it. The option being already set, as it is by default, doesn't means that closing and reopening the database is pointless.
May 7 '14 #20

P: 17
Oh Ok Sorry about that. Let me try it again then
May 7 '14 #21

P: 17
Wow that worked. Thanks sooooooo much for the help. So glad. Is there a way to keep it enabled for that code though? When I go back out of the database and come back in it doesn't work again unless I enable it.
May 7 '14 #22

Seth Schrock
Expert 2.5K+
P: 2,886
You can add the containing folder to your trusted locations.
May 7 '14 #23

P: 17
Ok, how do I do that?
May 7 '14 #24

Seth Schrock
Expert 2.5K+
P: 2,886
In the same trusted locations box, instead of selecting the Message Bar tab, choose Trusted Locations and then click Add New Location and then you can browse to the folder that contains your database and then click OK.
May 7 '14 #25

P: 17
Just tried it and my work does not allow me to do that. So I will have to see if I can have an IT person do it for me. Thanks again for your help
May 7 '14 #26

Seth Schrock
Expert 2.5K+
P: 2,886
I'm glad that I work in IT and have admin privileges on my computer :)
May 7 '14 #27

P: 17
Yeah I wish that I did. :)
May 7 '14 #28

P: 5
This was very helpful thank you!
Jun 12 '18 #29

Post your reply

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