473,387 Members | 1,510 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,387 software developers and data experts.

Help in clearing form data!!!

22
Hi!

I'm loosing my nerves!!! I normaly use Access 2003 but for the moment Access 2007 Trial and i'm not familiar with the VBA language nor SQL.

I'm making a form where i add data into text/list boxes and then press a button to run an append query to have it inserted into a table. Simple, yes but how can i make the data to clear from my form on for example mouse up (when I have clicked the button). I know one can use the setvalue command by using macros, but the pain in specifing every single object and having "millions" of macros isn't really an attractive option. So couldn't it be done using the expression builder??

Tank you
Jan 17 '07 #1
23 19193
MMcCarthy
14,534 Expert Mod 8TB
Hi!

I'm loosing my nerves!!! I normaly use Access 2003 but for the moment Access 2007 Trial and i'm not familiar with the VBA language nor SQL.

I'm making a form where i add data into text/list boxes and then press a button to run an append query to have it inserted into a table. Simple, yes but how can i make the data to clear from my form on for example mouse up (when I have clicked the button). I know one can use the setvalue command by using macros, but the pain in specifing every single object and having "millions" of macros isn't really an attractive option. So couldn't it be done using the expression builder??

Tank you
In VBA the following command will clear all unbound controls

Expand|Select|Wrap|Line Numbers
  1. Me.Refresh
Mary
Jan 17 '07 #2
Phille
22
Thank you for the fast response,

I try to add the command but when I click my button the screen flickers slightly but nothing happens, my textbox still has the text i wrote???

Any advice?

Thanks
Jan 17 '07 #3
nico5038
3,080 Expert 2GB
Try:
me.RecordSource=me.RecordSource

Looks funny, but should work

Nic;o)
Jan 17 '07 #4
Phille
22
Still completly lost.

I've made a new form thats not bound to enything added a textbox (unbound) and a button. I set the OnClick to both Me.Refresh and me.RecordSource=me.RecordSource.

------------------------------------------------------------------
Private Sub Command2_Click()
Me.Refresh
End Sub
------------------------------------------------------------------
Private Sub Command2_Click()
Me.RecordSource=Me.RecordSource
End Sub
------------------------------------------------------------------

So what am i doing wrong???
Jan 17 '07 #5
nico5038
3,080 Expert 2GB
For emptying a field on an unbound form use:

Me.Fieldname = ""
Me.refresh

Nic;o)
Jan 17 '07 #6
Phille
22
yiiiihaaa!!!

It worked thanks everybody, 2 days of misserable pain is over.

If someone still has a command for clearing the whole record/form please post but with this I will already come a long way.

Thanks again
Jan 17 '07 #7
NeoPa
32,556 Expert Mod 16PB
This routine (Public in a non-object module) should do it for you.
There is flexibility to treat different object types differently with a small change to the Select Case statement.
Expand|Select|Wrap|Line Numbers
  1. 'ClearUnbound empties all controls on an unbound form.
  2. Public Sub ClearUnbound(frmMe As Form)
  3.     Dim varCtrl As Variant
  4.  
  5.     For Each varCtrl In frmMe.Controls
  6.         With varCtrl
  7.             Select Case .ControlType
  8.             Case acCheckBox, acComboBox, acListBox, acTextBox
  9.                 .Value = Null
  10.             End Select
  11.         End With
  12.     Next varCtrl
  13. End Sub
Jan 18 '07 #8
Phille
22
Thanks

But I can't get it to work it starts whining about the privet sub

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command45_Click()
  2. 'ClearUnbound empties all controls on an unbound form.
  3. Public Sub ClearUnbound(frmMe As Form)
  4.     Dim varCtrl As Variant
  5.  
  6.     For Each varCtrl In frmMe.Controls
  7.         With varCtrl
  8.             Select Case .ControlType
  9.             Case acCheckBox, acComboBox, acListBox, acTextBox
  10.                 .Value = Null
  11.             End Select
  12.         End With
  13.     Next varCtrl
  14. End Sub
  15. End Sub
Please remember that for the moment being, Iknow nothing about VBA
Jan 19 '07 #9
NeoPa
32,556 Expert Mod 16PB
That's because you're not doing it quite right (All right - it's all wrong).
That's not a problem though, we all have to start somewhere.
Follow these instructions :
  1. Open the database in Access.
  2. Switch to the VBA Window (Alt-F11).
  3. Insert / Module.
  4. Copy the ClearUnbound procedure in.
  5. Switch back to Access (Alt-F11 again).
  6. Open your form in Design Mode.
  7. Right-click on your Command45 control and select Build Event...
  8. Type in the code below :
    Expand|Select|Wrap|Line Numbers
    1. Call ClearUnbound(frmMe:=Me)
  9. Debug / Compile ... (Project Name).
  10. Save.
Jan 19 '07 #10
Phille
22
Thanks allot

I used to be a computer administrator at a small firm but never had the need of programming, so I just let it be. Then one day someone came in and asked me if I knew anything about the "For Dummies" series of books (which I didn't), but I answerd "Oh them, they are for morrons".

Guess what! I just ordered 400 pages of "Programming Access 2007 For Dummies"

What do we learn from this? Just keep your mouth shut or your a morron : )

Anyways, Thanks it worked like a charm, and you have lightened a few lights for me, though have quite a few more to go and I'll be there.
Jan 19 '07 #11
NeoPa
32,556 Expert Mod 16PB
Well, we'll be happy to help light you on your way :)
Oh, and by the way, do you think we all haven't been there or thereabouts ourselves once?
Jan 19 '07 #12
Phille
22
Yes I know everyone has been here, it was just the preassure valve that bursted.

You know the fealing? You think you know what you are doing but it just won't work, copy/pasting, reading helpfiles etc for hours.

This is called anger management : )
Jan 19 '07 #13
MMcCarthy
14,534 Expert Mod 8TB
Well, we'll be happy to help light you on your way :)
Oh, and by the way, do you think we all haven't been there or thereabouts ourselves once?
Speak for yourself. I always knew everything. I was borned that way :D
Jan 19 '07 #14
NeoPa
32,556 Expert Mod 16PB
Yes I know everyone has been here, it was just the preassure valve that bursted.

You know the fealing? You think you know what you are doing but it just won't work, copy/pasting, reading helpfiles etc for hours.

This is called anger management : )
I suppose that's one way of doing it - if you can't find anyone nearby to punch I suppose :D
Jan 20 '07 #15
NeoPa
32,556 Expert Mod 16PB
Speak for yourself. I always knew everything. I was programmed that way :D
Fair point Mary.
Jan 20 '07 #16
MMcCarthy
14,534 Expert Mod 8TB
Fair point Mary.
Don't think I didn't notice the edit. How double damn dare you. :D
Jan 20 '07 #17
NeoPa
32,556 Expert Mod 16PB
Don't think I didn't notice the edit. How double damn dare you. :D
Well - it was worth a try :D (I didn't tamper with your post notice).
Jan 20 '07 #18
Phille
22
Hi again

So! I haven't yet receved my book so mean while I'm still stuck knowing a little less than nothing about VBA programming.

Could there be anything done about the code giving an error when there are controlled objects on the form. For the moment I have a textbox that gets data depending of values from other controls. For example just ignoring those objects.

Thanks in advance
Jan 31 '07 #19
NeoPa
32,556 Expert Mod 16PB
I've changed the original code somewhat. Considering this is a function to clear unbound controls, it's only right that there should be a check to see if the control is unbound ;)
See if this works better for you.
Expand|Select|Wrap|Line Numbers
  1. 'ClearUnbound empties all controls on an unbound form.
  2. Public Sub ClearUnbound(frmMe As Form)
  3.     Dim varCtrl As Variant
  4.  
  5.     For Each varCtrl In frmMe.Controls
  6.         With varCtrl
  7.             Select Case .ControlType
  8.             Case acCheckBox, acComboBox, acListBox, acTextBox
  9.                 If IsNull(.ControlSource) Then .Value = Null
  10.             End Select
  11.         End With
  12.     Next varCtrl
  13. End Sub
Jan 31 '07 #20
Phille
22
Thanks for the response but now it dosen't clear anything??
Any other suggestions?

Thanks
Feb 1 '07 #21
NeoPa
32,556 Expert Mod 16PB
Sorry. I expect the check of (.ControlSource) should be for an empty string rather than Null. Try this amended version :
Expand|Select|Wrap|Line Numbers
  1. 'ClearUnbound empties all controls on an unbound form.
  2. Public Sub ClearUnbound(frmMe As Form)
  3.     Dim varCtrl As Variant
  4.  
  5.     For Each varCtrl In frmMe.Controls
  6.         With varCtrl
  7.             Select Case .ControlType
  8.             Case acCheckBox, acComboBox, acListBox, acTextBox
  9.                 If .ControlSource = "" Then .Value = Null
  10.             End Select
  11.         End With
  12.     Next varCtrl
  13. End Sub
Feb 1 '07 #22
Phille
22
IT WORKS!!!

Thanks a million : )
Feb 1 '07 #23
NeoPa
32,556 Expert Mod 16PB
Everyone sounds surprised when my code works! :D

Seriously, I'm pleased it's done the trick.
Feb 1 '07 #24

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

Similar topics

10
by: Gregory A Greenman | last post by:
I'm trying to write a program in vb.net to automate filling out a series of forms on a website. There are three forms I need to fill out in sequence. The first one is urlencoded. My program is...
0
by: Norman Fritag | last post by:
Hi there I have a form wish is used to doubt check data been entered before it is updated to the main table. I structured the form into 3 tabs of which the first on represents the total amount...
1
by: abdul bari | last post by:
Hi I have a standard html form which is generated by an XSL sheet. The form data is submitted to the server and is passed on to file.aspx for processing. However file.aspx is refreshed every 5...
7
by: Mark Waser | last post by:
Hi all, I'm trying to post multipart/form-data to a web page but seem to have run into a wall. I'm familiar with RFC 1867 and have done this before (with AOLServer and Tcl) but just can't seem...
15
by: tmax | last post by:
PHP Pros: I have a simple html form that submits data to a php script, which processes it, and then redisplays the same page, but with a "thank you" message in place of the html form. This is...
1
by: David P. Donahue | last post by:
I have an ASP .NET website where users submit comments and, depending on whether or not the web service accepting the comments returns an error, the form uses this.page.registerstartupscript() to...
2
by: Msharma | last post by:
Hello all, This is my first flirtation with PHP and I could use some help on this. This is what I'm trying to do. I capture data from an HTML form and catch the data in a PHP script. Now I want to...
6
by: smk17 | last post by:
I've spent the last few minutes searching for this question and I found an answer, but it wasn't quite what the client wanted. I have a simple online form where the user needs to fill out five...
1
by: starter08 | last post by:
Hi, I have a C++ routine(client-side) which uploads an xml file to a web server by making a socket connection and sending all the post request through that socket. On the server side I have a cgi...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
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,...
0
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...
0
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,...

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.