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

Subform Filter / Update Issues

I have a subform built into a form in Access 2007. I would like the user to be able to filter the subform using their own criteria by right clicking the column header in the subform. Once the user has the subform record set filtered as they want I would like them to be able to click a button on the main form that will set the yes/no field [EXCLUDE_LINE] in the filtered subfom data set to true.

Here is the code I have been trying to get to work and it keeps resulting in an error "Few to parameters, Expected 1"? I have searched and tried some different code as well with the same results. Any help is greatly appreciated.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command196_Click()
  2. Dim strSql As String
  3.  
  4. strSql = "UPDATE tblUtilizationDataAll SET EXCLUDE_LINE = -1 "
  5. strSql = strSql & "WHERE PROJECT_NAME = '" & Me.Text81 & "' And " & Me.tblUtilizationDataAll_subform.Form.Filter & ";"
  6. CurrentDb.Execute strSql
  7.  
  8. Me.tblUtilizationDataAll_subform.Requery
  9. Me.Requery
  10.  
  11. End Sub
  12.  
Thanks - Mike
Mar 5 '08 #1
4 2571
Stewart Ross
2,545 Expert Mod 2GB
...
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command196_Click()
  2. Dim strSql As String
  3.  
  4. strSql = "UPDATE tblUtilizationDataAll SET EXCLUDE_LINE = -1 "
  5. strSql = strSql & "WHERE PROJECT_NAME = '" & Me.Text81 & "' And " & Me.tblUtilizationDataAll_subform.Form.Filter & ";"
  6. CurrentDb.Execute strSql
  7.  
  8. Me.tblUtilizationDataAll_subform.Requery
  9. Me.Requery
  10.  
  11. End Sub
  12.  
Hi Mike. You're referring to the subform's filter property, which is a string value, but unlike the other part of your WHERE clause you are not using single quotes on either side to indicate a string literal. Replace what is listed as line 5 above with:
Expand|Select|Wrap|Line Numbers
  1. strSql = strSql & "WHERE PROJECT_NAME = '" & Me.Text81 & "' And '" & Me.tblUtilizationDataAll_subform.Form.Filter & "';"
-Stewart
Mar 6 '08 #2
Thank you Stewart for the response. The query is not picking up the criteria from the filter for some reason. The code runs but updates all of the records under each project name?
Mar 10 '08 #3
Stewart Ross
2,545 Expert Mod 2GB
Thank you Stewart for the response. The query is not picking up the criteria from the filter for some reason. The code truns but updates all of the records under each project name?
Hi Mike. Your code does not filter the subform; it simply picks up any filter that is already set and applies it as a WHERE clause to your update of the records. I did not comment on this before, as it seemed to me that you would not have used an UPDATE statement unless you really needed to change values in records.

If you could let us know what the main form does, and what you really want to achieve when you mention filtering the subform I am sure we can advise you on how to go about it. It looks to me that the UPDATE stetement is an entirely unnecessary step if what you really want is not to update anything but to apply a filter to your subform. To filter the form you need to set its filter first, then set the form's filteron property true.

I wonder if your underlying table design is appropriate? Subforms are often used to represent tables linked in one-to-many relations, with the main form based on the one-side table and the subform the many-side (e.g. a form displaying a purchase order in the main form and the order lines (the items items being purchased) in the subform).

Please tell us a bit more about what you want to do, and the relevant fields of the tables underlying your current form/subform, so we can advise you more suitably how to proceed.

-Stewart
Mar 10 '08 #4
Stewart, the main and the subform do have a one to many relationship. The subform is showing line item detail for the project in the main form. The idea was the the user could filter the line items in the subform and exclude them from the project. Through the exclusions the totals for the project on the main form would adjust. Anyway, I was able to use an update loop to accomplish what I needed.

Regards,

Mike
Mar 25 '08 #5

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

Similar topics

2
by: Andante.in.Blue | last post by:
Hi everyone! I was wondering if there is a away to use Access 97's build in filter-by-form function but restrict its effect to just the subform. I have a parent form that shows the major...
2
by: Galina | last post by:
Hello I have an application in MS Access 2000. I have a form, which includes a subform. The subform is based on a table, but locked for any editing. There is Edit button. When clicked, it starts a...
11
by: Ian Ornstein | last post by:
in posting http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&newwindow=1&selm=bmEK9.43452%24lj.1060600%40read1.cgocable.net Lyle showed us that an ADODB.Recordset can be created and attached to a...
0
by: CSDunn | last post by:
Hello, In Access ADP's that connect to SQL Server databases, any time I have a situation where I have a combo box in a main form that looks up a record in a subform, the subform record source has...
1
by: aintnorock | last post by:
I have a relatively simple relational database. One of my forms is based on a query with a 3 parameter sort: Status / Priority / Customer. When I open the form, the records are sorted properly. ...
1
by: MLH | last post by:
I have a form with a subform control on it listing records returned by a saved query named UnbilledVehicles. I would like to put command buttons on the main form to apply dynamic filters to the...
9
by: Ecohouse | last post by:
I have a main form with two subforms. The first subform has the child link to the main form identity key. subform1 - Master Field: SK Child Field: TrainingMasterSK The second subform has a...
5
by: Tgavin8 | last post by:
Hi I am creating a database for a company who will be selling canvas art. I am currently having issues creating the Invoice screen where I am using a subform for the sales line items. On the...
2
by: patriciashoe | last post by:
Greeting All I have several public variables which I use to build a filter string that I would like to use when I open a form and several associated sub forms. I have set the value of the combo...
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
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
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,...
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,...
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.