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

Filtering a form with checkboxes

This question has probably been asked, I just can't find it - sorry if I am double posting.

I have a form that displays cselect info from my homebrew database (ie Name, date brewed, date bottled, alc. content, what kind of batch it is (wine, beer, mead) and certain check boxes for things like if the batch has been bottled or is completed)

From this screen I would like to have a few check boxes along the bottom in the form footer that will filter the data in the form detail section. Like filter out everything that is beer (a text field) and is bottled (a yes/no field). I guess I just need a good idea to start with. some help with the code would be helpful as well. I'm not new, just rusty :)
Jan 10 '08 #1
7 11642
Minion
108 Expert 100+
This question has probably been asked, I just can't find it - sorry if I am double posting.

I have a form that displays cselect info from my homebrew database (ie Name, date brewed, date bottled, alc. content, what kind of batch it is (wine, beer, mead) and certain check boxes for things like if the batch has been bottled or is completed)

From this screen I would like to have a few check boxes along the bottom in the form footer that will filter the data in the form detail section. Like filter out everything that is beer (a text field) and is bottled (a yes/no field). I guess I just need a good idea to start with. some help with the code would be helpful as well. I'm not new, just rusty :)
Now that you've made me thirsty I guess I'll lend a bump in the right direction.

What you're going to probably want to do here is a create one sub that will apply the filter. This sub will hold all the possible filters you'll need (actually it will create it) and will be accessed by clicking the various check boxes. I don't have enough particulars at the moment on how the form and table are constructed to put together any code that would make sense but I'll give you the general idea of what will need to be done.

Essentially, you'll want the sub to create a string that will act as filter for the form (strFilter for the following example). Then use the filter property for the form. The following code is how you would do that.

Expand|Select|Wrap|Line Numbers
  1. Me.Filter = strFilter
  2. Me.FilterOn = True
  3. Me.Requery
  4.  
Hope this gets you moving in the right direction. If you want to provide a little more details about the construction of the table and form maybe I can put together some more exacting code.

Hope this helps.

- Minion -
Jan 10 '08 #2
Well, the continuous form just displays certain fields from my database, enough to get the basic idea from each batch. to the left of each row is a button to take you to another form to edit the fields. The continuouos form displays all records, but not all fields. When i apply one of these filters, i really only need to be looking at 3 yes/no fields (Future, Bottled, Completed) and one text field for the type (beer, wine, mead, or soda). i can do this pretty easily by right clicking on a field that i want to filter, but the check boxes would just make it nice!

i will try to play around with the idea you had, but might need a little more help.

if you can help me with this, consider a bottle of mead yours! (you just have to wait for it to age 6 to 12 months, my last batch was just bottle last week) :^)
Jan 10 '08 #3
I am doin something similar, but am having trouble getting the script working

Private Sub Pending_Changes_Click()
Dim strSQL As String
If IsNull(Me.{POL_Change_Allocated) Then
' If the combo is Null, use the whole table as the RecordSource.
Me.RecordSource = "OCP_Base_tables"
Else
strSQL = "SELECT DISTINCTROW tblOCP_Base_Tables.* FROM tblOCP_Base_Tables " & _
"INNER JOIN tblPOL_Actions ON " & _
"tblOCP_Base_Tables.OCP_Ref = tblPOL_Actions.OCP_Ref " & _
"WHERE tblPOL_Actions.POL_Change_Allocated = " & Me.Pending_Changes & ";"
Me.RecordSource = strSQL
End If
End Sub


POL Change allocated is a tickbox, if this is blank it means that the change record hasnt been updated so I am trying to get my button to return all these records on my forms page. I have to tables linked into my forms as a form "OCP_Base_tables" and subform "POL_Actions"

maybe we can mdle through together.
Jan 11 '08 #4
araman
53
I'm not an access wizard but i believe if your checkbox is a yes/no then unchecked is "false"
Jan 11 '08 #5
Minion
108 Expert 100+
First off Araman is correct that a checkbox reads a couple values, but the easiest to work with is "True/False" so I made this alteration. Now bear with me as I don't have the db to work with I'm having to work from knowledge along and I'm still building it. I've changed a couple things around that should help. Mainly just how the recordsets were being called. I don't believe the orginal would have called the recordset correctly.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Pending_Changes_Click()
  2. Dim strSQL As String
  3. Dim dbs As DAO.Database
  4.  
  5. Set dbs = CurrentDb
  6.  
  7.     If Not (Me.POL_Change_Allocated) Then
  8.         'If combo is empty, use whole table as RS
  9.         Me.RecordSource = dbs.OpenRecordset("OCP_Base_tables")
  10.     Else
  11.         strSQL = "SELECT DISTINCTROW tblOCP_Base_Tables.* FROM tblOCP_Base_Tables " & _
  12.         "INNER JOIN tblPOL_Actions ON " & _
  13.         "tblOCP_Base_Tables.OCP_Ref = tblPOL_Actions.OCP_Ref " & _
  14.         "WHERE tblPOL_Actions.POL_Change_Allocated = " & Me.Pending_Changes & ";"
  15.  
  16.         Me.RecordSource = dbs.OpenRecordset(strSQL)
  17.     End If
  18.  
  19. End Sub
  20.  
Another possible way of accomplishing this would be to use the filter property of the form and filter the records when the box is checked or unchecked. If we can't get this working that may be a possibility.

Hope this actually works and helps.

- Minion -
Jan 11 '08 #6
Minion,

I changed part of the sub to

Private Sub Command56_Click()
Dim strSQL As String
Dim dbs As DAO.Database

Set dbs = CurrentDb

If Not (Me.Command56) Then

As that is the name of the button.

I then get an error for the follwoing line _

Me.RecordSource

Help states

Type mismatch (Error 13)


Visual Basic is able to convert and coerce many values to accomplish data type assignments that weren't possible in earlier versions. However, this error can still occur and has the following causes and solutions:

The variable or property isn't of the correct type. For example, a variable that requires an integer value can't accept a string value unless the whole string can be recognized as an integer.
Try to make assignments only between compatible data types. For example, an Integer can always be assigned to a Long, a Single can always be assigned to a Double, and any type (except a user-defined type) can be assigned to a Variant.

An object was passed to a procedure that is expecting a single property or value.
Pass the appropriate single property or call a method appropriate to the object.

A module or project name was used where an expression was expected, for example:
Debug.Print MyModule

Specify an expression that can be displayed.

You attempted to mix traditional Basic error handling with Variant values having the Error subtype (10, vbError), for example:
Error CVErr(n)

To regenerate an error, you must map it to an intrinsic Visual Basic or a user-defined error, and then generate that error.

A CVErr value can't be converted to Date. For example:
MyVar = CDate(CVErr(9))

Use a Select Case statement or some similar construct to map the return of CVErr to such a value.

At run time, this error typically indicates that a Variant used in an expression has an incorrect subtype, or a Variant containing an array appears in a Print # statement.
To print arrays, create a loop that displays each element individually.

For additional information, select the item in question and press F1 (in Windows) or HELP (on the Macintosh).

Does this mean that recordsource needs to be changed to the table it is looking at?
Jan 14 '08 #7
I bet you are sick I ever joined this site.
Jan 14 '08 #8

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

Similar topics

2
by: Edward | last post by:
The following html / javascript code produces a simple form with check boxes. There is also a checkbox that 'checks all' form checkboxes hotmail style: <html> <head> <title></title> </head>...
3
by: Aionius | last post by:
Good day to all. I have this problem in JavaScript. I have a form (textbox) which accepts a series of numbers in format 9999-9999-9. Now i want to filter all inputs to the textbox. let's say...
7
by: Nathan Bloomfield | last post by:
Hi All, I am hoping someone out there will be kind enough to find out where my code is going wrong. The current code is inefficiant but hopefully it will convey the data I require to be...
2
by: Aravind | last post by:
Hi folks. I have a form, frmHistory, which has 4 command buttons: Sort Title (cmdSortTitle), Sort Name (cmdSortName), Due Today (cmdDueToday), and Due List (cmdDueList). Sort Title and Sort...
1
by: Aravind | last post by:
Hi folks. My database project has the following: -------------------------------------------------------------------------------- tables: Member: MemName, MemNo , MemType, CourseFaculty...
2
by: Sean | last post by:
Greetings all, I am attempting to make a form that will filter through several tables that (I believe) have refretial integrity. I am pulling data from several tables into the form and i would...
4
by: Dave | last post by:
I am having difficulty filtering a form as the user types in a onchange event here is my code strFilter = cboCriteria.Value & " LIKE '" & Me!txtCriteria.text & "*" & "'" If Len(strFilter ) 0...
12
by: hlebforprimeminister | last post by:
Hi I want to filter records on a continuous form(FRM_SUPPT) by one of the fields, SW_ID. FRM_SUPPT has a text box ( bound to SW_ID) and two drop-down lists that are bound also. The three...
4
by: novoselent | last post by:
This seems like it should be an easy thing, but I think I'm missing something simple here...or I'm just going about it all wrong... Using Access 2003 I have a form that lists vehicle service...
7
by: viki1967 | last post by:
I need one function javascript that: 1) when I enter in this htm page I see enabled only checkbox of categories A, M and T; checkboxes of microcategories all disabled; 2-a) If I select the...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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...

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.