Checkboxes Choice..

HZM

Registered User.
Local time
Tomorrow, 00:21
Joined
Mar 11, 2015
Messages
23
Hey...
I've got a Form that contains a subform from a query of a table..
That Form limits the contents of the subform (datasheet view) with different things like date period and 4 checkboxes each one hold name of place (Alex,Aswan & Luxor).
SO, what i want to do is that when i check the checkbox of "Alex" the query of the subform show only records for places in "Alex" depending on the (Place) field in the table of the query that contain all places (Alex,Aswan & Luxor) & on un-checking the Alex Checkbox the subform do not show the Alex records..
Same with the Aswan & Luxor checkboxes..
Is there anyway of doing that by VBA ?!
 
Yes, it's called form filters. Then it's a matter of setting code for the value of the checkbox if it's true or not.
Here is an Example of a filter.


The following example uses the ApplyFilter method to display only records that contain the name "King" in the LastName field:
VBA

PHP:
DoCmd.ApplyFilter , "LastName = 'King'"
 
Well, i don't want to make "Filter".. i just want to show only the values of the checkboxes, cause filter can be edited in the subform itself without using codes.
So, yes i want a code for the value of the Alexandria checkbox if it's true or not (means when it's true the value = "Alexandria", and if not = "" ) and same for the other checkboxes (Aswan & Luxor)!!
 
If you don't want to use filter, then you've one one chose left, then set the form's recordsourse from code, where you take in account which checkbox(es) is marked.
 
Actually i didn't get what you said, did you mean that i have to enter code into the subform's recordsource of certain field that limits data to the value of the checked checkbox ? if so, then can you tell me how to write this code ?! O.o
 
... did you mean that i have to enter code into the subform's recordsource ..
No - I wrote, you've to change the form's recordsourse from code, not to put in code in the subform's recordsource!
I read your first post again, and I see you've a query for the subforms recordsource, can't you modify that query to also take in account which checkbox(es) is marked?
 
The thing is that the table & the query DOES NOT contain checkbox field..
They contain a text field names [Place] that has values of "Alexandria,Aswan & Luxor" !!
And in the form i want to only show records that it's [Place] field contain value of Alexandria (for example) on checking the checkbox with name "Alexandria"..
Is there any idea for that ? :rolleyes:
 
Yes - then we are back to post #4, set the form's recordsourse from code, where you take in account which checkbox(es) is marked.
Something like the below code, (it is not tested so it may have to be change).
Code:
  Dim SqlString As String

  SqlString = "Select [Place] from ATable WHERE "
  If Me.Alex Then
    SqlString = SqlString & " [Place]='Alex' OR "
  End If
  If Me.Alexandria Then
    SqlString = SqlString & " [Place]='Alexandria' OR "
  End If
  SqlString = Left(SqlString, Len(SqlString) - 4)
  Me.RecordSource = SqlString
  Me.Requery
If you can't get it, then post your database with some sample data, (zip it) + name of the form.
 
I would really appreciate that ..

Here's a Sample of the DB
Form load on opening
 

Attachments

Try it now!
In this case, filter has been the correct to use as mention by another member.
 

Attachments

Users who are viewing this thread

Back
Top Bottom