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

Clear Form Fields and ReQuery

I currently have Multiple Field Search Query that feeds from a main form. Query Result are dependent upon what is entered into the main form

Multiple Field Search Query SQL
Expand|Select|Wrap|Line Numbers
  1. SELECT tblMainTable.ItemID, tblMainTable.FiscalYear, tblMainTable.StoreName, tblMainTable.Item, tbleMainTable.ItemName
  2. WHERE (((tblMainTable.FiscalYear)=[Forms]![frmMainForm]![txtFiscalYear]) AND ((tblMainTable.StoreName)=[Forms]![frmMainForm]!)) 

On the Main Form (frmMainForm) is a Multiple Field Seach Form pulling data from the multiple field search queary. I have a Sub Form (subfrmMainForm) that shows the results of the query.

Using the following VBA codes for command button upon click (Query and Clear)

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdbtnQuery_Click()
  2. ' Query Command Button 
  3. Me.subformStoreItemSearch.Requery
  4. End Sub
  5.  
  6. Private Sub cmdbtnClear_Click()
  7. 'When button is clicked clears the field on the main form
  8. Me.txtFiscalYear = ""
  9. Me.cboStoreName = ""
  10. Me.cboItem = ""
  11. Me.txtItemName = ""
  12. Me.cboStoreLocation = ""
  13. Me.txtState = ""
  14. Me.txtCity = ""
  15.  
  16. 'Requery subform
  17. Me.SubfromStoreItemSearch.Requery
  18. Me.subformStoreItemSearch.SetFocus
  19. DoCmd.GoToRecord , , acLast
  20. Me.txtFicalYear.SetFocus
  21.  
  22. End Sub
The Query Command Button works and the user can manually change the info on the form and hit the command button Query to requery the subform. However; when the user hits the Clear Command Button (to auto clear all the fields) the query button does not work anymore. I have to close out the form and to reopen it for the Query Button to work again.
Oct 11 '16 #1

✓ answered by jforbes

ADezii may have anther option, but based on your Query, I would try this code for your Clear Button:
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdbtnClear_Click()
  2.  'When button is clicked clears the field on the main form
  3.  Me.txtFiscalYear.Value = Null
  4.  Me.cboStoreName.Value = Null
  5.  Me.cboItem.Value = Null
  6.  Me.txtItemName.Value = Null
  7.  Me.cboStoreLocation.Value = Null
  8.  Me.txtState.Value = Null
  9.  Me.txtCity.Value = Null
  10.  ...
  11.  End Sub

5 16165
jforbes
1,107 Expert 1GB
What do you mean it doesn't work anymore? Are you getting an error? Is the Form going Blank? Does everything seem to work OK, but the filtering is not returning any results?

It would be helpful to see the SQL of the Query used for subformStoreItemSearch.

Lastly, if I were to guess at a solution, I would try the following change (this is purely a guess):
Expand|Select|Wrap|Line Numbers
  1. Me.txtFiscalYear = year(now())
  2. Me.cboStoreName = "*"
  3. Me.cboItem = "*"
  4. Me.txtItemName = "*"
  5. Me.cboStoreLocation = "*"
  6. Me.txtState = "*"
  7. Me.txtCity = "*"
Oct 12 '16 #2
ADezii
8,834 Expert 8TB
  1. Unless I am mistaken, the Data Source for your Sub-Form is
    Expand|Select|Wrap|Line Numbers
    1. SELECT tblMainTable.ItemID, tblMainTable.FiscalYear, tblMainTable.StoreName, tblMainTable.Item, tbleMainTable.ItemName
    2. WHERE (((tblMainTable.FiscalYear)=[Forms]![frmMainForm]![txtFiscalYear]) AND ((tblMainTable.StoreName)=[Forms]![frmMainForm]!))
  2. Once you clear the Search Fields on the Main Form, the Query will return No Records since both Criteria have not been satisfied.
    Expand|Select|Wrap|Line Numbers
    1. tblMainTable.FiscalYear=[Forms]![frmMainForm]![txtFiscalYear] AND tblMainTable.StoreName=[Forms]![frmMainForm]![txtStoreName]
  3. The Sub-Form, being based on this Query, will be Empty.
  4. P.S. - ![txtStoreName] was omitted from the Query SQL.
Oct 12 '16 #3
JForbes and Adezii

The data source is a Query (qryMainTableInput) pulling data tblMainTable based on what is inputted in a Form (frmMainFormInput)

Query SQL below

Expand|Select|Wrap|Line Numbers
  1. SELECT tblMainTable.ItemID, tblMainTable.FiscalYear, tblMainTable.StoreName, tblMainTable.Item, tblMainTable.ItemDescription, tblMainTable.AuthQty, tblMainTable.GEOLOC, tblMainTable.GEOLOCName
  2. FROM tblMainTable
  3. WHERE (((tblMainTable.FiscalYear)=[Forms]![frmMainFormInput]![txtFiscalYear]) AND ((tblMainTable.StoreName)=[Forms]![frmMainFormInput]![cboStoreName]) AND ((tblMainTable.Item)=[Forms]![frmMainFormInput]![cboItem])) OR (((tblMainTable.FiscalYear)=[Forms]![frmMainFormInput]![txtFiscalYear]) AND ((tblMainTable.StoreName)=[Forms]![frmMainFormInput]![cboStoreName]) AND (([Forms]![frmMainFormInput]![cboItem]) Is Null)) OR (((tblMainTable.FiscalYear)=[Forms]![frmMainFormInput]![txtFiscalYear]) AND ((tblMainTable.Item)=[Forms]![frmMainFormInput]![cboItem]) AND (([Forms]![frmMainFormInput]![cboStoringName]) Is Null)) OR (((tblMainTable.FiscalYear)=[Forms]![frmMainFormInput]![txtFiscalYear]) AND (([Forms]![frmMainFormInput]![cboItem]) Is Null) AND (([Forms]![frmMainFormInput]![cboStoringName]) Is Null));
  4.  
The Subform (SubfromStoreItemSearch) for frmMainFormInput is based off of the Query Results (SQL above) based on the inputs of unbound text/combo boxes in frmMainFormInput.

Created a Query button on frmMainFormInput to requery SubfromStoreItemSearch.

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdbtnQuery_Click()
  2. ' Query Command Button 
  3. Me.subformStoreItemSearch.Requery
  4. End Sub
  5.  
This Command button works with no issue, user is allowed to change the unbound text/combo boxes manually and requery the subform to show the results in the subform. However; when I inserted the below code for a Clear the fields in the frmMainFormInput so the user do not have to manually clear the text and combo boxes in frmMainFromInput and reset for a new query

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdbtnClear_Click()
  2. 'When button is clicked clears the field on the main form
  3. Me.txtFiscalYear = ""
  4. Me.cboStoreName = ""
  5. Me.cboItem = ""
  6. Me.txtItemName = ""
  7. Me.cboStoreLocation = ""
  8. Me.txtState = ""
  9. Me.txtCity = ""
  10.  
  11. 'Requery subform
  12. Me.SubfromStoreItemSearch.Requery
  13. Me.subformStoreItemSearch.SetFocus
  14. DoCmd.GoToRecord , , acLast
  15. Me.txtFicalYear.SetFocus
  16.  
  17. End Sub
Clear command button works, however; when user types in new info to Query (by Fiscal Year, Store Name, Item) and the user hits the Query Command Button the subform remains blank. But; when I go into the actual query (qryMainTableInput) the results show up. Or If the user exits out of the frmMainFromInput and re-opens the form the user can use the query button to populate the subform results. (until the clear command is executed).

Is their something wrong w/ the Clear Command Button VBA where it the form is not resetting for the user to query. Should I just delete the Clear Command Button and have the User just manually clear the form to query new info.

Hope this is clear as mud

Thanks
Oct 12 '16 #4
jforbes
1,107 Expert 1GB
ADezii may have anther option, but based on your Query, I would try this code for your Clear Button:
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdbtnClear_Click()
  2.  'When button is clicked clears the field on the main form
  3.  Me.txtFiscalYear.Value = Null
  4.  Me.cboStoreName.Value = Null
  5.  Me.cboItem.Value = Null
  6.  Me.txtItemName.Value = Null
  7.  Me.cboStoreLocation.Value = Null
  8.  Me.txtState.Value = Null
  9.  Me.txtCity.Value = Null
  10.  ...
  11.  End Sub
Oct 12 '16 #5
JFordes, Thanks for the reply/input and it finally is working.
Oct 12 '16 #6

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

Similar topics

4
by: bnp | last post by:
Hi All, I am quite new the JavaScript. Basically I am a C++ programmer, but now I am working on JavaScript since last 5 days. I have a problem regarding the form validation. I have created a...
4
by: karenmiddleol | last post by:
I have the following form the user enters the From and to period and presses the Submit button and the form fields are cleared once the submit button is pressed. Is there a way I can keep the...
6
by: David Jarman | last post by:
I'm a Newbie to this group and would be grateful for assistance as I get up to speed. I'm working on my first Access project and need to be able to 'clear' fields on a form when first loaded....
5
by: Dave | last post by:
Hi, I have an asp.net page with a form. When the submit button is clicked it sends an email. When the page reloads the form fields are still filled with the info that just got submitted. ...
2
by: tshad | last post by:
Is there a way to tell a screen on Postback to clear all the objects (or put them back to their defaults on Postback)? At the moment, I am just going through and setting them manually before...
7
by: Chuck Anderson | last post by:
I'm pretty much a JavaScript novice. I'm good at learning by example and changing those examples to suit my needs. That said .... ..... I have some select fields in a form I created for a...
1
by: sujathaTamtam | last post by:
i want solution to reset the form fields. i have one salutation field( Mr,Ms,Other) when we click on other,the other text box will appear and we enter some text. when we click on reset button...
5
by: plumba | last post by:
Ok, another query.... I have a checkbox at the bottom of my form which when checked unhides a <div> block which displays the submit button. The problem I have is when the clear form button is...
6
by: mcupito | last post by:
I have a form where users can enter a new record (or multiple). If a user decides to not enter anything, it keeps throwing errors (my exceptions to prevent null fields from being entered). The...
4
by: nwtech75 | last post by:
Greetings All, I'm a new comer here, came across some of your posts while looking for a solution to a simple problem. Seems to be a good community so I thought I would drop in for a visit and see if...
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: 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?
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
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
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
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,...

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.