469,306 Members | 1,662 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,306 developers. It's quick & easy.

How to create a button to clear a subform from a main form

I have a query by form set up.

I coded and can get the fields on the form to clear by the click of a button, but how do I make the subform clear, too?

The main form has a "Clear" button and in the "event procedure" I placed the following code:

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdClear_Click()
  3.     Me.txtFname = Null
  4.     Me.txtLname = Null
  5.     Me.cboCountry = Null
  6.     Me.cboDistribution = Null
  7.     Me.cboPlatform = Null
  8.     Me.cboState = Null
  9.     Me.cboStatus = Null
  10.     Me.cboType = Null
  12. End Sub
When the button is clicked, all of the criteria fields clear but I am not sure how to make it so the subform with the results below it clear, too.

I would greatly appreciate assistance.

Thank you.
Aug 25 '10 #1
6 12639
Jerry Maiapu
259 100+
The format to access a particula field in a subform from main/parent form is
Expand|Select|Wrap|Line Numbers
  1. Forms!MainFormName!Subformname!Subform_Textbox_name
so try something like
Expand|Select|Wrap|Line Numbers
  1. Forms!MainForm Name!Subform Name!Subform_Textbox_name1=Null
  2. Forms!MainFormName!Subformname!Subform_Textbox_name2=Null
or else try this format.
Expand|Select|Wrap|Line Numbers
  1. me!Subformname!Subform_Textbox_name
Aug 25 '10 #2
374 256MB
i just use
Expand|Select|Wrap|Line Numbers
  1. Me.subfrmcontrolname.form.controlonsubfrm = ""

Where subfrmcontrolname is the name of your subform on your main form. Not the name of the actual subform as per your convention on your database window.

The control name of the subform can differ to the actual form loaded within it.
Aug 26 '10 #3
Thank you very much for your help.

However, I found I could clear the form by simply placing
Expand|Select|Wrap|Line Numbers
  1. Me.CONTROLNAME = Null
  2. (etc, if more)
  3. Me.frmNAMEOFSubform.Requery
So once you hit "clear", it requeries based on nothing and produces nothing, clearing the subform.

I don't know if this is the correct way, but it produced nice results for me.

I greatly appreciate your guidance.
Aug 27 '10 #4
32,173 Expert Mod 16PB
If that's what you're trying to do, then that's the correct way. Unfortunately your question gave no clue that you desired that effect. In fact it gave an example that implied otherwise. We can only answer your question if you ask it properly.
Aug 27 '10 #5
Can't read a woman's mind? Just kidding...

I see, thank you NeoPa, I will consider that in the future.

I was just not sure how to ask it I suppose. But utilizing other's advise helped me learn a few more things and I really appreciate that.

Have a very pleasant weekend.
Aug 27 '10 #6
32,173 Expert Mod 16PB
Can't read a woman's mind?
I expect that's it :D

Of course I do realise expressing one's question clearly can be difficult (If I didn't realise that by now I really would be stupid), but I like to bring attention to the importance of it when I get the opportunity.

You'd be surprised how many members don't appreciate that in a forum environment, without all the extra clues you get talking face to face or seeing the project (DB) in front of you, the expression of the question is so much more important.

I know I come off as grumpy sometimes, which is something I can live with if I must, but I'm trying to guide those members to a better way of using the facilities (here and elsewhere of course).

Anyway, have a very pleasant weekend yourself and I'm very glad you managed to resolve your issue :)
Aug 27 '10 #7

Post your reply

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

Similar topics

3 posts views Thread by Mike Cocker | last post: by
7 posts views Thread by Cues Plus | last post: by
3 posts views Thread by Harvey | last post: by
1 post views Thread by google | last post: by
1 post views Thread by abracad_1999 | last post: by
3 posts views Thread by Richard | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.