Can I still use check boxes?

  • Thread starter Thread starter sebastico
  • Start date Start date
S

sebastico

Hello
I have spent weeks trying to use Check boxes on my form in Access 2003. I
received samples of code from this forum, but unfortunately I'm still a
beginner in vba. My head aches but I hope this time I'll be lucky and I can
use correctly you help.

In http://allenbrowne.com/NoYesNo.html web site. 'The interface does not
offer Check Box as an option, but you can set the property programmatically
like this:

CurrentDb.TableDefs("Table1").Fields("Field1").Properties("DisplayControl") =
CInt(acCheckBox)'.' Where in my table I can write this code?

In my db MyTable has two fields ComID as PK (string) and NombCom as string.
I would really appreciate if you can tell me step by step how to write the
code.

On the other hand, I have been using a textbox on a form to search and works
well

If Not IsNull(Me.txtComID) Then
strWhere = strWhere & "([ComID] Like """ & Me.txtComID & """) AND "
End If
Thank for your help
 
Try entering the expression in the Immediate Window.

Press Ctrl+G to open the Immediate Window.
Substitute your table name for Table1, and your field name for Field1.
Have the table closed at the time you do this.
After you press Enter, you won't get any message unless there is an error.
 
Allen.

I can see the check box in my table in DataSheet. Thank you very much indeed.
Now. How can I use this check box in your search form?I have been using your
search form example successfully.
In my form I have this code to filter using a txtbox and I know that using
check box will allow user to check one or more check boxes

This is the code I'm using to search by txtbox:
Private Sub cmdFilter_Click()
Dim strWhere As String
Dim lngLen As Long

If Not IsNull(Me.txtFilterAID) Then
strWhere = strWhere & "([AID] = """ & Me.txtFilterAID & """) AND "
End If

If Not IsNull(Me.txtFilterB) Then
strWhere = strWhere & "( Like ""*" & Me.txtFilterB & """) AND "
End If

If Not IsNull(Me.txtFilterC) Then
strWhere = strWhere & "([C] Like ""*" & Me.txtFilterC & """) AND "
End If

If Not IsNull(Me.txtFilterD) Then **** Here is where I need to search using
the Check box***
strWhere = strWhere & "([D] Like ""*" & Me.txtFilterD & """) AND "
End If

Many thanks.

Allen Browne said:
Try entering the expression in the Immediate Window.

Press Ctrl+G to open the Immediate Window.
Substitute your table name for Table1, and your field name for Field1.
Have the table closed at the time you do this.
After you press Enter, you won't get any message unless there is an error.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.


sebastico said:
Hello
I have spent weeks trying to use Check boxes on my form in Access 2003. I
received samples of code from this forum, but unfortunately I'm still a
beginner in vba. My head aches but I hope this time I'll be lucky and I
can
use correctly you help.

In http://allenbrowne.com/NoYesNo.html web site. 'The interface does not
offer Check Box as an option, but you can set the property
programmatically
like this:

CurrentDb.TableDefs("Table1").Fields("Field1").Properties("DisplayControl")
=
CInt(acCheckBox)'.' Where in my table I can write this code?

In my db MyTable has two fields ComID as PK (string) and NombCom as
string.
I would really appreciate if you can tell me step by step how to write the
code.

On the other hand, I have been using a textbox on a form to search and
works
well

If Not IsNull(Me.txtComID) Then
strWhere = strWhere & "([ComID] Like """ & Me.txtComID & """) AND "
End If
Thank for your help
.
 
You can append the true/false value of a check box into a WHERE string,
e.g.:
strWhere = strWhere & "(MyYesNoField = " & Nz(Me.Check1, False) & ") AND
"

This doesn't allow you to leave it blank (so it doesn't filter on this
field.) An unbound check box can be null, but that's not very visually
useful to the user. I think you're better using a combo box where the user
can choose yes or no or leave it blank.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.


sebastico said:
Allen.

I can see the check box in my table in DataSheet. Thank you very much
indeed.
Now. How can I use this check box in your search form?I have been using
your
search form example successfully.
In my form I have this code to filter using a txtbox and I know that using
check box will allow user to check one or more check boxes

This is the code I'm using to search by txtbox:
Private Sub cmdFilter_Click()
Dim strWhere As String
Dim lngLen As Long

If Not IsNull(Me.txtFilterAID) Then
strWhere = strWhere & "([AID] = """ & Me.txtFilterAID & """) AND "
End If

If Not IsNull(Me.txtFilterB) Then
strWhere = strWhere & "( Like ""*" & Me.txtFilterB & """) AND "
End If

If Not IsNull(Me.txtFilterC) Then
strWhere = strWhere & "([C] Like ""*" & Me.txtFilterC & """) AND "
End If

If Not IsNull(Me.txtFilterD) Then **** Here is where I need to search
using
the Check box***
strWhere = strWhere & "([D] Like ""*" & Me.txtFilterD & """) AND "
End If

Many thanks.

Allen Browne said:
Try entering the expression in the Immediate Window.

Press Ctrl+G to open the Immediate Window.
Substitute your table name for Table1, and your field name for Field1.
Have the table closed at the time you do this.
After you press Enter, you won't get any message unless there is an
error.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.


sebastico said:
Hello
I have spent weeks trying to use Check boxes on my form in Access 2003.
I
received samples of code from this forum, but unfortunately I'm still a
beginner in vba. My head aches but I hope this time I'll be lucky and
I
can
use correctly you help.

In http://allenbrowne.com/NoYesNo.html web site. 'The interface does
not
offer Check Box as an option, but you can set the property
programmatically
like this:

CurrentDb.TableDefs("Table1").Fields("Field1").Properties("DisplayControl")
=
CInt(acCheckBox)'.' Where in my table I can write this code?

In my db MyTable has two fields ComID as PK (string) and NombCom as
string.
I would really appreciate if you can tell me step by step how to write
the
code.

On the other hand, I have been using a textbox on a form to search and
works
well

If Not IsNull(Me.txtComID) Then
strWhere = strWhere & "([ComID] Like """ & Me.txtComID & """) AND "
End If
Thank for your help
.
 
Allen

I'm really confused, I know is my little skills in programming.
With this code:

If Not IsNull(Me.txtFilterAID) Then
strWhere = strWhere & "([AID] Like """ & Me.txtFilterID & """) AND "
End If

When I type a number in txtFilterAID and click the cmdFilter the form shows
the records.The field AID is a string.

Nevertheless, with this code:
'If NotIsNull(Me.chkA) Then
'strWhere = strWhere & "(MyYesNofield = & Nz(Me.chkA, False) &" And ""
'End If

When I click the chkA and then click the cmdFilter codeVBA displays Compile
error: Sub or Function not defined.
The piece of code NotIsNull is selected in blue colour.

Could you tell me what I'm doing wrong? Please

What I'm trying to do is if I click in a check box (chkA) and then I click
the cmdFilter the form will displays the filtered records in the form.

The table that I'm trying to filter records has the filed A without the
check box.
I hope my message is clear. I'm so sad due to my mother tongue is not English.

Hoping to hear from you

Allen Browne said:
You can append the true/false value of a check box into a WHERE string,
e.g.:
strWhere = strWhere & "(MyYesNoField = " & Nz(Me.Check1, False) & ") AND
"

This doesn't allow you to leave it blank (so it doesn't filter on this
field.) An unbound check box can be null, but that's not very visually
useful to the user. I think you're better using a combo box where the user
can choose yes or no or leave it blank.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.


sebastico said:
Allen.

I can see the check box in my table in DataSheet. Thank you very much
indeed.
Now. How can I use this check box in your search form?I have been using
your
search form example successfully.
In my form I have this code to filter using a txtbox and I know that using
check box will allow user to check one or more check boxes

This is the code I'm using to search by txtbox:
Private Sub cmdFilter_Click()
Dim strWhere As String
Dim lngLen As Long

If Not IsNull(Me.txtFilterAID) Then
strWhere = strWhere & "([AID] = """ & Me.txtFilterAID & """) AND "
End If

If Not IsNull(Me.txtFilterB) Then
strWhere = strWhere & "( Like ""*" & Me.txtFilterB & """) AND "
End If

If Not IsNull(Me.txtFilterC) Then
strWhere = strWhere & "([C] Like ""*" & Me.txtFilterC & """) AND "
End If

If Not IsNull(Me.txtFilterD) Then **** Here is where I need to search
using
the Check box***
strWhere = strWhere & "([D] Like ""*" & Me.txtFilterD & """) AND "
End If

Many thanks.

Allen Browne said:
Try entering the expression in the Immediate Window.

Press Ctrl+G to open the Immediate Window.
Substitute your table name for Table1, and your field name for Field1.
Have the table closed at the time you do this.
After you press Enter, you won't get any message unless there is an
error.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.


Hello
I have spent weeks trying to use Check boxes on my form in Access 2003.
I
received samples of code from this forum, but unfortunately I'm still a
beginner in vba. My head aches but I hope this time I'll be lucky and
I
can
use correctly you help.

In http://allenbrowne.com/NoYesNo.html web site. 'The interface does
not
offer Check Box as an option, but you can set the property
programmatically
like this:

CurrentDb.TableDefs("Table1").Fields("Field1").Properties("DisplayControl")
=
CInt(acCheckBox)'.' Where in my table I can write this code?

In my db MyTable has two fields ComID as PK (string) and NombCom as
string.
I would really appreciate if you can tell me step by step how to write
the
code.

On the other hand, I have been using a textbox on a form to search and
works
well

If Not IsNull(Me.txtComID) Then
strWhere = strWhere & "([ComID] Like """ & Me.txtComID & """) AND "
End If
Thank for your help

.

.
 
Your quotes are not right.
You need to replace MyYesNofield with the name of your yes/no field.

strWhere = strWhere & "(MyYesNofield = " & Nz(Me.chkA, False) & " AND "

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.


sebastico said:
Allen

I'm really confused, I know is my little skills in programming.
With this code:

If Not IsNull(Me.txtFilterAID) Then
strWhere = strWhere & "([AID] Like """ & Me.txtFilterID & """) AND "
End If

When I type a number in txtFilterAID and click the cmdFilter the form
shows
the records.The field AID is a string.

Nevertheless, with this code:
'If NotIsNull(Me.chkA) Then
'strWhere = strWhere & "(MyYesNofield = & Nz(Me.chkA, False) &" And ""
'End If

When I click the chkA and then click the cmdFilter codeVBA displays
Compile
error: Sub or Function not defined.
The piece of code NotIsNull is selected in blue colour.

Could you tell me what I'm doing wrong? Please

What I'm trying to do is if I click in a check box (chkA) and then I
click
the cmdFilter the form will displays the filtered records in the form.

The table that I'm trying to filter records has the filed A without the
check box.
I hope my message is clear. I'm so sad due to my mother tongue is not
English.

Hoping to hear from you

Allen Browne said:
You can append the true/false value of a check box into a WHERE string,
e.g.:
strWhere = strWhere & "(MyYesNoField = " & Nz(Me.Check1, False) & ")
AND
"

This doesn't allow you to leave it blank (so it doesn't filter on this
field.) An unbound check box can be null, but that's not very visually
useful to the user. I think you're better using a combo box where the
user
can choose yes or no or leave it blank.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.


sebastico said:
Allen.

I can see the check box in my table in DataSheet. Thank you very much
indeed.
Now. How can I use this check box in your search form?I have been using
your
search form example successfully.
In my form I have this code to filter using a txtbox and I know that
using
check box will allow user to check one or more check boxes

This is the code I'm using to search by txtbox:
Private Sub cmdFilter_Click()
Dim strWhere As String
Dim lngLen As Long

If Not IsNull(Me.txtFilterAID) Then
strWhere = strWhere & "([AID] = """ & Me.txtFilterAID & """) AND "
End If

If Not IsNull(Me.txtFilterB) Then
strWhere = strWhere & "( Like ""*" & Me.txtFilterB & """) AND "
End If

If Not IsNull(Me.txtFilterC) Then
strWhere = strWhere & "([C] Like ""*" & Me.txtFilterC & """) AND "
End If

If Not IsNull(Me.txtFilterD) Then **** Here is where I need to search
using
the Check box***
strWhere = strWhere & "([D] Like ""*" & Me.txtFilterD & """) AND "
End If

Many thanks.

:

Try entering the expression in the Immediate Window.

Press Ctrl+G to open the Immediate Window.
Substitute your table name for Table1, and your field name for Field1.
Have the table closed at the time you do this.
After you press Enter, you won't get any message unless there is an
error.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.


Hello
I have spent weeks trying to use Check boxes on my form in Access
2003.
I
received samples of code from this forum, but unfortunately I'm
still a
beginner in vba. My head aches but I hope this time I'll be lucky
and
I
can
use correctly you help.

In http://allenbrowne.com/NoYesNo.html web site. 'The interface does
not
offer Check Box as an option, but you can set the property
programmatically
like this:

CurrentDb.TableDefs("Table1").Fields("Field1").Properties("DisplayControl")
=
CInt(acCheckBox)'.' Where in my table I can write this code?

In my db MyTable has two fields ComID as PK (string) and NombCom as
string.
I would really appreciate if you can tell me step by step how to
write
the
code.

On the other hand, I have been using a textbox on a form to search
and
works
well

If Not IsNull(Me.txtComID) Then
strWhere = strWhere & "([ComID] Like """ & Me.txtComID & """) AND "
End If
Thank for your help

.

.
 
Hello Allen
I have to modify my table (with the check box field) and then linked to the
realtions. I let you know if I success.
Thank you very much indeed.
Allen Browne said:
Your quotes are not right.
You need to replace MyYesNofield with the name of your yes/no field.

strWhere = strWhere & "(MyYesNofield = " & Nz(Me.chkA, False) & " AND "

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.


sebastico said:
Allen

I'm really confused, I know is my little skills in programming.
With this code:

If Not IsNull(Me.txtFilterAID) Then
strWhere = strWhere & "([AID] Like """ & Me.txtFilterID & """) AND "
End If

When I type a number in txtFilterAID and click the cmdFilter the form
shows
the records.The field AID is a string.

Nevertheless, with this code:
'If NotIsNull(Me.chkA) Then
'strWhere = strWhere & "(MyYesNofield = & Nz(Me.chkA, False) &" And ""
'End If

When I click the chkA and then click the cmdFilter codeVBA displays
Compile
error: Sub or Function not defined.
The piece of code NotIsNull is selected in blue colour.

Could you tell me what I'm doing wrong? Please

What I'm trying to do is if I click in a check box (chkA) and then I
click
the cmdFilter the form will displays the filtered records in the form.

The table that I'm trying to filter records has the filed A without the
check box.
I hope my message is clear. I'm so sad due to my mother tongue is not
English.

Hoping to hear from you

Allen Browne said:
You can append the true/false value of a check box into a WHERE string,
e.g.:
strWhere = strWhere & "(MyYesNoField = " & Nz(Me.Check1, False) & ")
AND
"

This doesn't allow you to leave it blank (so it doesn't filter on this
field.) An unbound check box can be null, but that's not very visually
useful to the user. I think you're better using a combo box where the
user
can choose yes or no or leave it blank.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.



Allen.

I can see the check box in my table in DataSheet. Thank you very much
indeed.
Now. How can I use this check box in your search form?I have been using
your
search form example successfully.
In my form I have this code to filter using a txtbox and I know that
using
check box will allow user to check one or more check boxes

This is the code I'm using to search by txtbox:
Private Sub cmdFilter_Click()
Dim strWhere As String
Dim lngLen As Long

If Not IsNull(Me.txtFilterAID) Then
strWhere = strWhere & "([AID] = """ & Me.txtFilterAID & """) AND "
End If

If Not IsNull(Me.txtFilterB) Then
strWhere = strWhere & "( Like ""*" & Me.txtFilterB & """) AND "
End If

If Not IsNull(Me.txtFilterC) Then
strWhere = strWhere & "([C] Like ""*" & Me.txtFilterC & """) AND "
End If

If Not IsNull(Me.txtFilterD) Then **** Here is where I need to search
using
the Check box***
strWhere = strWhere & "([D] Like ""*" & Me.txtFilterD & """) AND "
End If

Many thanks.

:

Try entering the expression in the Immediate Window.

Press Ctrl+G to open the Immediate Window.
Substitute your table name for Table1, and your field name for Field1.
Have the table closed at the time you do this.
After you press Enter, you won't get any message unless there is an
error.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.


Hello
I have spent weeks trying to use Check boxes on my form in Access
2003.
I
received samples of code from this forum, but unfortunately I'm
still a
beginner in vba. My head aches but I hope this time I'll be lucky
and
I
can
use correctly you help.

In http://allenbrowne.com/NoYesNo.html web site. 'The interface does
not
offer Check Box as an option, but you can set the property
programmatically
like this:

CurrentDb.TableDefs("Table1").Fields("Field1").Properties("DisplayControl")
=
CInt(acCheckBox)'.' Where in my table I can write this code?

In my db MyTable has two fields ComID as PK (string) and NombCom as
string.
I would really appreciate if you can tell me step by step how to
write
the
code.

On the other hand, I have been using a textbox on a form to search
and
works
well

If Not IsNull(Me.txtComID) Then
strWhere = strWhere & "([ComID] Like """ & Me.txtComID & """) AND "
End If
Thank for your help

.

.

.
 
Yes, you will certainly have the problem of constantly having to modify your
table (and everything else that depends on it) when you use lots of yes/no
fields like that.

Is there any chance I can talk you into using a correctly normalized design
for your tables instead? See:
Don't use Yes/No fields to store preferences
at:
http://allenbrowne.com/casu-23.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.


sebastico said:
Hello Allen
I have to modify my table (with the check box field) and then linked to
the
realtions. I let you know if I success.
Thank you very much indeed.
Allen Browne said:
Your quotes are not right.
You need to replace MyYesNofield with the name of your yes/no field.

strWhere = strWhere & "(MyYesNofield = " & Nz(Me.chkA, False) & " AND
"

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.


sebastico said:
Allen

I'm really confused, I know is my little skills in programming.
With this code:

If Not IsNull(Me.txtFilterAID) Then
strWhere = strWhere & "([AID] Like """ & Me.txtFilterID & """) AND "
End If

When I type a number in txtFilterAID and click the cmdFilter the form
shows
the records.The field AID is a string.

Nevertheless, with this code:
'If NotIsNull(Me.chkA) Then
'strWhere = strWhere & "(MyYesNofield = & Nz(Me.chkA, False) &" And
""
'End If

When I click the chkA and then click the cmdFilter codeVBA displays
Compile
error: Sub or Function not defined.
The piece of code NotIsNull is selected in blue colour.

Could you tell me what I'm doing wrong? Please

What I'm trying to do is if I click in a check box (chkA) and then I
click
the cmdFilter the form will displays the filtered records in the form.

The table that I'm trying to filter records has the filed A without the
check box.
I hope my message is clear. I'm so sad due to my mother tongue is not
English.

Hoping to hear from you

:

You can append the true/false value of a check box into a WHERE
string,
e.g.:
strWhere = strWhere & "(MyYesNoField = " & Nz(Me.Check1, False) &
")
AND
"

This doesn't allow you to leave it blank (so it doesn't filter on this
field.) An unbound check box can be null, but that's not very visually
useful to the user. I think you're better using a combo box where the
user
can choose yes or no or leave it blank.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.



Allen.

I can see the check box in my table in DataSheet. Thank you very
much
indeed.
Now. How can I use this check box in your search form?I have been
using
your
search form example successfully.
In my form I have this code to filter using a txtbox and I know that
using
check box will allow user to check one or more check boxes

This is the code I'm using to search by txtbox:
Private Sub cmdFilter_Click()
Dim strWhere As String
Dim lngLen As Long

If Not IsNull(Me.txtFilterAID) Then
strWhere = strWhere & "([AID] = """ & Me.txtFilterAID & """) AND
"
End If

If Not IsNull(Me.txtFilterB) Then
strWhere = strWhere & "( Like ""*" & Me.txtFilterB & """) AND
"
End If

If Not IsNull(Me.txtFilterC) Then
strWhere = strWhere & "([C] Like ""*" & Me.txtFilterC & """) AND
"
End If

If Not IsNull(Me.txtFilterD) Then **** Here is where I need to
search
using
the Check box***
strWhere = strWhere & "([D] Like ""*" & Me.txtFilterD & """) AND
"
End If

Many thanks.

:

Try entering the expression in the Immediate Window.

Press Ctrl+G to open the Immediate Window.
Substitute your table name for Table1, and your field name for
Field1.
Have the table closed at the time you do this.
After you press Enter, you won't get any message unless there is an
error.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.


Hello
I have spent weeks trying to use Check boxes on my form in Access
2003.
I
received samples of code from this forum, but unfortunately I'm
still a
beginner in vba. My head aches but I hope this time I'll be
lucky
and
I
can
use correctly you help.

In http://allenbrowne.com/NoYesNo.html web site. 'The interface
does
not
offer Check Box as an option, but you can set the property
programmatically
like this:

CurrentDb.TableDefs("Table1").Fields("Field1").Properties("DisplayControl")
=
CInt(acCheckBox)'.' Where in my table I can write this code?

In my db MyTable has two fields ComID as PK (string) and NombCom
as
string.
I would really appreciate if you can tell me step by step how to
write
the
code.

On the other hand, I have been using a textbox on a form to
search
and
works
well

If Not IsNull(Me.txtComID) Then
strWhere = strWhere & "([ComID] Like """ & Me.txtComID & """) AND
"
End If
Thank for your help

.

.

.
 
Hello Allen
After reading your article, I see that my first table relationship design is
correct. That means I cannot use check box to filter records with my correct
design?
My idea to use check boxes is to allow user to select one or more checks in
the form to filter records. For example filtering by two years and two or
more. check boxes.
If check boxes is not good, how can I filter one or more fields in a txtbox?

Thank you very much.

Allen Browne said:
Yes, you will certainly have the problem of constantly having to modify your
table (and everything else that depends on it) when you use lots of yes/no
fields like that.

Is there any chance I can talk you into using a correctly normalized design
for your tables instead? See:
Don't use Yes/No fields to store preferences
at:
http://allenbrowne.com/casu-23.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.


sebastico said:
Hello Allen
I have to modify my table (with the check box field) and then linked to
the
realtions. I let you know if I success.
Thank you very much indeed.
Allen Browne said:
Your quotes are not right.
You need to replace MyYesNofield with the name of your yes/no field.

strWhere = strWhere & "(MyYesNofield = " & Nz(Me.chkA, False) & " AND
"

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.



Allen

I'm really confused, I know is my little skills in programming.
With this code:

If Not IsNull(Me.txtFilterAID) Then
strWhere = strWhere & "([AID] Like """ & Me.txtFilterID & """) AND "
End If

When I type a number in txtFilterAID and click the cmdFilter the form
shows
the records.The field AID is a string.

Nevertheless, with this code:
'If NotIsNull(Me.chkA) Then
'strWhere = strWhere & "(MyYesNofield = & Nz(Me.chkA, False) &" And
""
'End If

When I click the chkA and then click the cmdFilter codeVBA displays
Compile
error: Sub or Function not defined.
The piece of code NotIsNull is selected in blue colour.

Could you tell me what I'm doing wrong? Please

What I'm trying to do is if I click in a check box (chkA) and then I
click
the cmdFilter the form will displays the filtered records in the form.

The table that I'm trying to filter records has the filed A without the
check box.
I hope my message is clear. I'm so sad due to my mother tongue is not
English.

Hoping to hear from you

:

You can append the true/false value of a check box into a WHERE
string,
e.g.:
strWhere = strWhere & "(MyYesNoField = " & Nz(Me.Check1, False) &
")
AND
"

This doesn't allow you to leave it blank (so it doesn't filter on this
field.) An unbound check box can be null, but that's not very visually
useful to the user. I think you're better using a combo box where the
user
can choose yes or no or leave it blank.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.



Allen.

I can see the check box in my table in DataSheet. Thank you very
much
indeed.
Now. How can I use this check box in your search form?I have been
using
your
search form example successfully.
In my form I have this code to filter using a txtbox and I know that
using
check box will allow user to check one or more check boxes

This is the code I'm using to search by txtbox:
Private Sub cmdFilter_Click()
Dim strWhere As String
Dim lngLen As Long

If Not IsNull(Me.txtFilterAID) Then
strWhere = strWhere & "([AID] = """ & Me.txtFilterAID & """) AND
"
End If

If Not IsNull(Me.txtFilterB) Then
strWhere = strWhere & "( Like ""*" & Me.txtFilterB & """) AND
"
End If

If Not IsNull(Me.txtFilterC) Then
strWhere = strWhere & "([C] Like ""*" & Me.txtFilterC & """) AND
"
End If

If Not IsNull(Me.txtFilterD) Then **** Here is where I need to
search
using
the Check box***
strWhere = strWhere & "([D] Like ""*" & Me.txtFilterD & """) AND
"
End If

Many thanks.

:

Try entering the expression in the Immediate Window.

Press Ctrl+G to open the Immediate Window.
Substitute your table name for Table1, and your field name for
Field1.
Have the table closed at the time you do this.
After you press Enter, you won't get any message unless there is an
error.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.


Hello
I have spent weeks trying to use Check boxes on my form in Access
2003.
I
received samples of code from this forum, but unfortunately I'm
still a
beginner in vba. My head aches but I hope this time I'll be
lucky
and
I
can
use correctly you help.

In http://allenbrowne.com/NoYesNo.html web site. 'The interface
does
not
offer Check Box as an option, but you can set the property
programmatically
like this:

CurrentDb.TableDefs("Table1").Fields("Field1").Properties("DisplayControl")
=
CInt(acCheckBox)'.' Where in my table I can write this code?

In my db MyTable has two fields ComID as PK (string) and NombCom
as
string.
I would really appreciate if you can tell me step by step how to
write
the
code.

On the other hand, I have been using a textbox on a form to
search
and
works
well

If Not IsNull(Me.txtComID) Then
strWhere = strWhere & "([ComID] Like """ & Me.txtComID & """) AND
"
End If
Thank for your help

.

.

.

.
 
Okay, I think I must have missed your train of thought somewhere, so have
just re-read this thread.

You have a text field named NombCom. You have a form with 5 unbound check
boxes, representing 5 possible values in that field. You want to filter this
form, so that any record that matches the value associated with any of the
checked boxes gets included.

You'll need to build a filter string that looks like this:
NombCom IN ('Alfred','Betty','Charlene')

The code would look like this:

Dim strTmp As String
Dim lngLen As Long
strTmp = ""
If Me.CheckA.Value Then
strTmp = "'Alfred',"
End If
If Me.CheckB.Value Then
strTmp = strTmp & "'Betty',"
End If
'and so on to CheckE.
lngLen = Len(strTmp) - 1
If lngLen > 0 Then
strWhere = "NombCom IN (" & Left$(strTmp), lngLen) & ") AND "
End If
'and so on with the other filter options for your form.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.


sebastico said:
Hello Allen
After reading your article, I see that my first table relationship design
is
correct. That means I cannot use check box to filter records with my
correct
design?
My idea to use check boxes is to allow user to select one or more checks
in
the form to filter records. For example filtering by two years and two or
more. check boxes.
If check boxes is not good, how can I filter one or more fields in a
txtbox?

Thank you very much.

Allen Browne said:
Yes, you will certainly have the problem of constantly having to modify
your
table (and everything else that depends on it) when you use lots of
yes/no
fields like that.

Is there any chance I can talk you into using a correctly normalized
design
for your tables instead? See:
Don't use Yes/No fields to store preferences
at:
http://allenbrowne.com/casu-23.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.


sebastico said:
Hello Allen
I have to modify my table (with the check box field) and then linked to
the
realtions. I let you know if I success.
Thank you very much indeed.
:

Your quotes are not right.
You need to replace MyYesNofield with the name of your yes/no field.

strWhere = strWhere & "(MyYesNofield = " & Nz(Me.chkA, False) & "
AND
"

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.



Allen

I'm really confused, I know is my little skills in programming.
With this code:

If Not IsNull(Me.txtFilterAID) Then
strWhere = strWhere & "([AID] Like """ & Me.txtFilterID & """)
AND "
End If

When I type a number in txtFilterAID and click the cmdFilter the
form
shows
the records.The field AID is a string.

Nevertheless, with this code:
'If NotIsNull(Me.chkA) Then
'strWhere = strWhere & "(MyYesNofield = & Nz(Me.chkA, False) &"
And
""
'End If

When I click the chkA and then click the cmdFilter codeVBA displays
Compile
error: Sub or Function not defined.
The piece of code NotIsNull is selected in blue colour.

Could you tell me what I'm doing wrong? Please

What I'm trying to do is if I click in a check box (chkA) and then
I
click
the cmdFilter the form will displays the filtered records in the
form.

The table that I'm trying to filter records has the filed A without
the
check box.
I hope my message is clear. I'm so sad due to my mother tongue is
not
English.

Hoping to hear from you

:

You can append the true/false value of a check box into a WHERE
string,
e.g.:
strWhere = strWhere & "(MyYesNoField = " & Nz(Me.Check1, False)
&
")
AND
"

This doesn't allow you to leave it blank (so it doesn't filter on
this
field.) An unbound check box can be null, but that's not very
visually
useful to the user. I think you're better using a combo box where
the
user
can choose yes or no or leave it blank.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.



Allen.

I can see the check box in my table in DataSheet. Thank you very
much
indeed.
Now. How can I use this check box in your search form?I have been
using
your
search form example successfully.
In my form I have this code to filter using a txtbox and I know
that
using
check box will allow user to check one or more check boxes

This is the code I'm using to search by txtbox:
Private Sub cmdFilter_Click()
Dim strWhere As String
Dim lngLen As Long

If Not IsNull(Me.txtFilterAID) Then
strWhere = strWhere & "([AID] = """ & Me.txtFilterAID & """)
AND
"
End If

If Not IsNull(Me.txtFilterB) Then
strWhere = strWhere & "( Like ""*" & Me.txtFilterB & """)
AND
"
End If

If Not IsNull(Me.txtFilterC) Then
strWhere = strWhere & "([C] Like ""*" & Me.txtFilterC & """)
AND
"
End If

If Not IsNull(Me.txtFilterD) Then **** Here is where I need to
search
using
the Check box***
strWhere = strWhere & "([D] Like ""*" & Me.txtFilterD & """)
AND
"
End If

Many thanks.

:

Try entering the expression in the Immediate Window.

Press Ctrl+G to open the Immediate Window.
Substitute your table name for Table1, and your field name for
Field1.
Have the table closed at the time you do this.
After you press Enter, you won't get any message unless there is
an
error.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.


message
Hello
I have spent weeks trying to use Check boxes on my form in
Access
2003.
I
received samples of code from this forum, but unfortunately
I'm
still a
beginner in vba. My head aches but I hope this time I'll be
lucky
and
I
can
use correctly you help.

In http://allenbrowne.com/NoYesNo.html web site. 'The
interface
does
not
offer Check Box as an option, but you can set the property
programmatically
like this:

CurrentDb.TableDefs("Table1").Fields("Field1").Properties("DisplayControl")
=
CInt(acCheckBox)'.' Where in my table I can write this code?

In my db MyTable has two fields ComID as PK (string) and
NombCom
as
string.
I would really appreciate if you can tell me step by step how
to
write
the
code.

On the other hand, I have been using a textbox on a form to
search
and
works
well

If Not IsNull(Me.txtComID) Then
strWhere = strWhere & "([ComID] Like """ & Me.txtComID & """)
AND
"
End If
Thank for your help

.

.

.

.
 
Allen
I apologize for delay in writing, my computer was out of the web for a
couple of weeks.
Trying your code vba displays this message: Compile error: Expected: end of
statement.
Next line is coloured in yellow and the pointer in the , after (strTmp) is
coloured in blue.
strWhere = "NombCom IN (" & Left$(strTmp), lngLen) & ") AND "
How can I fix this error?

Many thanks in advance

Allen Browne said:
Okay, I think I must have missed your train of thought somewhere, so have
just re-read this thread.

You have a text field named NombCom. You have a form with 5 unbound check
boxes, representing 5 possible values in that field. You want to filter this
form, so that any record that matches the value associated with any of the
checked boxes gets included.

You'll need to build a filter string that looks like this:
NombCom IN ('Alfred','Betty','Charlene')

The code would look like this:

Dim strTmp As String
Dim lngLen As Long
strTmp = ""
If Me.CheckA.Value Then
strTmp = "'Alfred',"
End If
If Me.CheckB.Value Then
strTmp = strTmp & "'Betty',"
End If
'and so on to CheckE.
lngLen = Len(strTmp) - 1
If lngLen > 0 Then
strWhere = "NombCom IN (" & Left$(strTmp), lngLen) & ") AND "
End If
'and so on with the other filter options for your form.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.


sebastico said:
Hello Allen
After reading your article, I see that my first table relationship design
is
correct. That means I cannot use check box to filter records with my
correct
design?
My idea to use check boxes is to allow user to select one or more checks
in
the form to filter records. For example filtering by two years and two or
more. check boxes.
If check boxes is not good, how can I filter one or more fields in a
txtbox?

Thank you very much.

Allen Browne said:
Yes, you will certainly have the problem of constantly having to modify
your
table (and everything else that depends on it) when you use lots of
yes/no
fields like that.

Is there any chance I can talk you into using a correctly normalized
design
for your tables instead? See:
Don't use Yes/No fields to store preferences
at:
http://allenbrowne.com/casu-23.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.



Hello Allen
I have to modify my table (with the check box field) and then linked to
the
realtions. I let you know if I success.
Thank you very much indeed.
:

Your quotes are not right.
You need to replace MyYesNofield with the name of your yes/no field.

strWhere = strWhere & "(MyYesNofield = " & Nz(Me.chkA, False) & "
AND
"

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.



Allen

I'm really confused, I know is my little skills in programming.
With this code:

If Not IsNull(Me.txtFilterAID) Then
strWhere = strWhere & "([AID] Like """ & Me.txtFilterID & """)
AND "
End If

When I type a number in txtFilterAID and click the cmdFilter the
form
shows
the records.The field AID is a string.

Nevertheless, with this code:
'If NotIsNull(Me.chkA) Then
'strWhere = strWhere & "(MyYesNofield = & Nz(Me.chkA, False) &"
And
""
'End If

When I click the chkA and then click the cmdFilter codeVBA displays
Compile
error: Sub or Function not defined.
The piece of code NotIsNull is selected in blue colour.

Could you tell me what I'm doing wrong? Please

What I'm trying to do is if I click in a check box (chkA) and then
I
click
the cmdFilter the form will displays the filtered records in the
form.

The table that I'm trying to filter records has the filed A without
the
check box.
I hope my message is clear. I'm so sad due to my mother tongue is
not
English.

Hoping to hear from you

:

You can append the true/false value of a check box into a WHERE
string,
e.g.:
strWhere = strWhere & "(MyYesNoField = " & Nz(Me.Check1, False)
&
")
AND
"

This doesn't allow you to leave it blank (so it doesn't filter on
this
field.) An unbound check box can be null, but that's not very
visually
useful to the user. I think you're better using a combo box where
the
user
can choose yes or no or leave it blank.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.



Allen.

I can see the check box in my table in DataSheet. Thank you very
much
indeed.
Now. How can I use this check box in your search form?I have been
using
your
search form example successfully.
In my form I have this code to filter using a txtbox and I know
that
using
check box will allow user to check one or more check boxes

This is the code I'm using to search by txtbox:
Private Sub cmdFilter_Click()
Dim strWhere As String
Dim lngLen As Long

If Not IsNull(Me.txtFilterAID) Then
strWhere = strWhere & "([AID] = """ & Me.txtFilterAID & """)
AND
"
End If

If Not IsNull(Me.txtFilterB) Then
strWhere = strWhere & "( Like ""*" & Me.txtFilterB & """)
AND
"
End If

If Not IsNull(Me.txtFilterC) Then
strWhere = strWhere & "([C] Like ""*" & Me.txtFilterC & """)
AND
"
End If

If Not IsNull(Me.txtFilterD) Then **** Here is where I need to
search
using
the Check box***
strWhere = strWhere & "([D] Like ""*" & Me.txtFilterD & """)
AND
"
End If

Many thanks.

:

Try entering the expression in the Immediate Window.

Press Ctrl+G to open the Immediate Window.
Substitute your table name for Table1, and your field name for
Field1.
Have the table closed at the time you do this.
After you press Enter, you won't get any message unless there is
an
error.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.


message
Hello
I have spent weeks trying to use Check boxes on my form in
Access
2003.
I
received samples of code from this forum, but unfortunately
I'm
still a
beginner in vba. My head aches but I hope this time I'll be
lucky
and
I
can
use correctly you help.

In http://allenbrowne.com/NoYesNo.html web site. 'The
interface
does
not
offer Check Box as an option, but you can set the property
programmatically
like this:

CurrentDb.TableDefs("Table1").Fields("Field1").Properties("DisplayControl")
=
CInt(acCheckBox)'.' Where in my table I can write this code?

In my db MyTable has two fields ComID as PK (string) and
NombCom
as
string.
I would really appreciate if you can tell me step by step how
to
write
the
code.

On the other hand, I have been using a textbox on a form to
search
and
works
well

If Not IsNull(Me.txtComID) Then
strWhere = strWhere & "([ComID] Like """ & Me.txtComID & """)
AND
"
End If
Thank for your help

.

.

.

.

.
 
There's a spurious bracket in that line:
strWhere = "NombCom IN (" & Left$(strTmp, lngLen) & ") AND "


--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.


sebastico said:
Allen
I apologize for delay in writing, my computer was out of the web for a
couple of weeks.
Trying your code vba displays this message: Compile error: Expected: end
of
statement.
Next line is coloured in yellow and the pointer in the , after (strTmp) is
coloured in blue.
strWhere = "NombCom IN (" & Left$(strTmp), lngLen) & ") AND "
How can I fix this error?

Many thanks in advance

Allen Browne said:
Okay, I think I must have missed your train of thought somewhere, so have
just re-read this thread.

You have a text field named NombCom. You have a form with 5 unbound check
boxes, representing 5 possible values in that field. You want to filter
this
form, so that any record that matches the value associated with any of
the
checked boxes gets included.

You'll need to build a filter string that looks like this:
NombCom IN ('Alfred','Betty','Charlene')

The code would look like this:

Dim strTmp As String
Dim lngLen As Long
strTmp = ""
If Me.CheckA.Value Then
strTmp = "'Alfred',"
End If
If Me.CheckB.Value Then
strTmp = strTmp & "'Betty',"
End If
'and so on to CheckE.
lngLen = Len(strTmp) - 1
If lngLen > 0 Then
strWhere = "NombCom IN (" & Left$(strTmp), lngLen) & ") AND "
End If
'and so on with the other filter options for your form.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.


sebastico said:
Hello Allen
After reading your article, I see that my first table relationship
design
is
correct. That means I cannot use check box to filter records with my
correct
design?
My idea to use check boxes is to allow user to select one or more
checks
in
the form to filter records. For example filtering by two years and two
or
more. check boxes.
If check boxes is not good, how can I filter one or more fields in a
txtbox?

Thank you very much.

:

Yes, you will certainly have the problem of constantly having to
modify
your
table (and everything else that depends on it) when you use lots of
yes/no
fields like that.

Is there any chance I can talk you into using a correctly normalized
design
for your tables instead? See:
Don't use Yes/No fields to store preferences
at:
http://allenbrowne.com/casu-23.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.



Hello Allen
I have to modify my table (with the check box field) and then linked
to
the
realtions. I let you know if I success.
Thank you very much indeed.
:

Your quotes are not right.
You need to replace MyYesNofield with the name of your yes/no
field.

strWhere = strWhere & "(MyYesNofield = " & Nz(Me.chkA, False) &
"
AND
"

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.



Allen

I'm really confused, I know is my little skills in programming.
With this code:

If Not IsNull(Me.txtFilterAID) Then
strWhere = strWhere & "([AID] Like """ & Me.txtFilterID & """)
AND "
End If

When I type a number in txtFilterAID and click the cmdFilter the
form
shows
the records.The field AID is a string.

Nevertheless, with this code:
'If NotIsNull(Me.chkA) Then
'strWhere = strWhere & "(MyYesNofield = & Nz(Me.chkA, False)
&"
And
""
'End If

When I click the chkA and then click the cmdFilter codeVBA
displays
Compile
error: Sub or Function not defined.
The piece of code NotIsNull is selected in blue colour.

Could you tell me what I'm doing wrong? Please

What I'm trying to do is if I click in a check box (chkA) and
then
I
click
the cmdFilter the form will displays the filtered records in the
form.

The table that I'm trying to filter records has the filed A
without
the
check box.
I hope my message is clear. I'm so sad due to my mother tongue is
not
English.

Hoping to hear from you

:

You can append the true/false value of a check box into a WHERE
string,
e.g.:
strWhere = strWhere & "(MyYesNoField = " & Nz(Me.Check1,
False)
&
")
AND
"

This doesn't allow you to leave it blank (so it doesn't filter
on
this
field.) An unbound check box can be null, but that's not very
visually
useful to the user. I think you're better using a combo box
where
the
user
can choose yes or no or leave it blank.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.


message

Allen.

I can see the check box in my table in DataSheet. Thank you
very
much
indeed.
Now. How can I use this check box in your search form?I have
been
using
your
search form example successfully.
In my form I have this code to filter using a txtbox and I
know
that
using
check box will allow user to check one or more check boxes

This is the code I'm using to search by txtbox:
Private Sub cmdFilter_Click()
Dim strWhere As String
Dim lngLen As Long

If Not IsNull(Me.txtFilterAID) Then
strWhere = strWhere & "([AID] = """ & Me.txtFilterAID &
""")
AND
"
End If

If Not IsNull(Me.txtFilterB) Then
strWhere = strWhere & "( Like ""*" & Me.txtFilterB &
""")
AND
"
End If

If Not IsNull(Me.txtFilterC) Then
strWhere = strWhere & "([C] Like ""*" & Me.txtFilterC &
""")
AND
"
End If

If Not IsNull(Me.txtFilterD) Then **** Here is where I need to
search
using
the Check box***
strWhere = strWhere & "([D] Like ""*" & Me.txtFilterD &
""")
AND
"
End If

Many thanks.

:

Try entering the expression in the Immediate Window.

Press Ctrl+G to open the Immediate Window.
Substitute your table name for Table1, and your field name
for
Field1.
Have the table closed at the time you do this.
After you press Enter, you won't get any message unless there
is
an
error.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.


message
Hello
I have spent weeks trying to use Check boxes on my form in
Access
2003.
I
received samples of code from this forum, but unfortunately
I'm
still a
beginner in vba. My head aches but I hope this time I'll
be
lucky
and
I
can
use correctly you help.

In http://allenbrowne.com/NoYesNo.html web site. 'The
interface
does
not
offer Check Box as an option, but you can set the property
programmatically
like this:

CurrentDb.TableDefs("Table1").Fields("Field1").Properties("DisplayControl")
=
CInt(acCheckBox)'.' Where in my table I can write this
code?

In my db MyTable has two fields ComID as PK (string) and
NombCom
as
string.
I would really appreciate if you can tell me step by step
how
to
write
the
code.

On the other hand, I have been using a textbox on a form to
search
and
works
well

If Not IsNull(Me.txtComID) Then
strWhere = strWhere & "([ComID] Like """ & Me.txtComID &
""")
AND
"
End If
Thank for your help

.

.

.

.

.
 
Allen

Many thanks for your kindness

I fix my error, however, vba displays in the same line of code: Compile
error:variable not defined and strWhere is coloured in blue.
The field NombComb in my table is Number. I have no idea how to fix this
error.
I really appreciated your help


sebastico said:
Allen
I apologize for delay in writing, my computer was out of the web for a
couple of weeks.
Trying your code vba displays this message: Compile error: Expected: end of
statement.
Next line is coloured in yellow and the pointer in the , after (strTmp) is
coloured in blue.
strWhere = "NombCom IN (" & Left$(strTmp), lngLen) & ") AND "
How can I fix this error?

Many thanks in advance

Allen Browne said:
Okay, I think I must have missed your train of thought somewhere, so have
just re-read this thread.

You have a text field named NombCom. You have a form with 5 unbound check
boxes, representing 5 possible values in that field. You want to filter this
form, so that any record that matches the value associated with any of the
checked boxes gets included.

You'll need to build a filter string that looks like this:
NombCom IN ('Alfred','Betty','Charlene')

The code would look like this:

Dim strTmp As String
Dim lngLen As Long
strTmp = ""
If Me.CheckA.Value Then
strTmp = "'Alfred',"
End If
If Me.CheckB.Value Then
strTmp = strTmp & "'Betty',"
End If
'and so on to CheckE.
lngLen = Len(strTmp) - 1
If lngLen > 0 Then
strWhere = "NombCom IN (" & Left$(strTmp), lngLen) & ") AND "
End If
'and so on with the other filter options for your form.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.


sebastico said:
Hello Allen
After reading your article, I see that my first table relationship design
is
correct. That means I cannot use check box to filter records with my
correct
design?
My idea to use check boxes is to allow user to select one or more checks
in
the form to filter records. For example filtering by two years and two or
more. check boxes.
If check boxes is not good, how can I filter one or more fields in a
txtbox?

Thank you very much.

:

Yes, you will certainly have the problem of constantly having to modify
your
table (and everything else that depends on it) when you use lots of
yes/no
fields like that.

Is there any chance I can talk you into using a correctly normalized
design
for your tables instead? See:
Don't use Yes/No fields to store preferences
at:
http://allenbrowne.com/casu-23.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.



Hello Allen
I have to modify my table (with the check box field) and then linked to
the
realtions. I let you know if I success.
Thank you very much indeed.
:

Your quotes are not right.
You need to replace MyYesNofield with the name of your yes/no field.

strWhere = strWhere & "(MyYesNofield = " & Nz(Me.chkA, False) & "
AND
"

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.



Allen

I'm really confused, I know is my little skills in programming.
With this code:

If Not IsNull(Me.txtFilterAID) Then
strWhere = strWhere & "([AID] Like """ & Me.txtFilterID & """)
AND "
End If

When I type a number in txtFilterAID and click the cmdFilter the
form
shows
the records.The field AID is a string.

Nevertheless, with this code:
'If NotIsNull(Me.chkA) Then
'strWhere = strWhere & "(MyYesNofield = & Nz(Me.chkA, False) &"
And
""
'End If

When I click the chkA and then click the cmdFilter codeVBA displays
Compile
error: Sub or Function not defined.
The piece of code NotIsNull is selected in blue colour.

Could you tell me what I'm doing wrong? Please

What I'm trying to do is if I click in a check box (chkA) and then
I
click
the cmdFilter the form will displays the filtered records in the
form.

The table that I'm trying to filter records has the filed A without
the
check box.
I hope my message is clear. I'm so sad due to my mother tongue is
not
English.

Hoping to hear from you

:

You can append the true/false value of a check box into a WHERE
string,
e.g.:
strWhere = strWhere & "(MyYesNoField = " & Nz(Me.Check1, False)
&
")
AND
"

This doesn't allow you to leave it blank (so it doesn't filter on
this
field.) An unbound check box can be null, but that's not very
visually
useful to the user. I think you're better using a combo box where
the
user
can choose yes or no or leave it blank.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.



Allen.

I can see the check box in my table in DataSheet. Thank you very
much
indeed.
Now. How can I use this check box in your search form?I have been
using
your
search form example successfully.
In my form I have this code to filter using a txtbox and I know
that
using
check box will allow user to check one or more check boxes

This is the code I'm using to search by txtbox:
Private Sub cmdFilter_Click()
Dim strWhere As String
Dim lngLen As Long

If Not IsNull(Me.txtFilterAID) Then
strWhere = strWhere & "([AID] = """ & Me.txtFilterAID & """)
AND
"
End If

If Not IsNull(Me.txtFilterB) Then
strWhere = strWhere & "( Like ""*" & Me.txtFilterB & """)
AND
"
End If

If Not IsNull(Me.txtFilterC) Then
strWhere = strWhere & "([C] Like ""*" & Me.txtFilterC & """)
AND
"
End If

If Not IsNull(Me.txtFilterD) Then **** Here is where I need to
search
using
the Check box***
strWhere = strWhere & "([D] Like ""*" & Me.txtFilterD & """)
AND
"
End If

Many thanks.

:

Try entering the expression in the Immediate Window.

Press Ctrl+G to open the Immediate Window.
Substitute your table name for Table1, and your field name for
Field1.
Have the table closed at the time you do this.
After you press Enter, you won't get any message unless there is
an
error.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.


message
Hello
I have spent weeks trying to use Check boxes on my form in
Access
2003.
I
received samples of code from this forum, but unfortunately
I'm
still a
beginner in vba. My head aches but I hope this time I'll be
lucky
and
I
can
use correctly you help.

In http://allenbrowne.com/NoYesNo.html web site. 'The
interface
does
not
offer Check Box as an option, but you can set the property
programmatically
like this:

CurrentDb.TableDefs("Table1").Fields("Field1").Properties("DisplayControl")
=
CInt(acCheckBox)'.' Where in my table I can write this code?

In my db MyTable has two fields ComID as PK (string) and
NombCom
as
string.
I would really appreciate if you can tell me step by step how
to
write
the
code.

On the other hand, I have been using a textbox on a form to
search
and
works
well

If Not IsNull(Me.txtComID) Then
strWhere = strWhere & "([ComID] Like """ & Me.txtComID & """)
 
Declare the variable, and make sure you don't have any missing references:
http://allenbrowne.com/ser-38.html

Can't debug this for you.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.


sebastico said:
Allen

Many thanks for your kindness

I fix my error, however, vba displays in the same line of code: Compile
error:variable not defined and strWhere is coloured in blue.
The field NombComb in my table is Number. I have no idea how to fix this
error.
I really appreciated your help


sebastico said:
Allen
I apologize for delay in writing, my computer was out of the web for a
couple of weeks.
Trying your code vba displays this message: Compile error: Expected: end
of
statement.
Next line is coloured in yellow and the pointer in the , after (strTmp)
is
coloured in blue.
strWhere = "NombCom IN (" & Left$(strTmp), lngLen) & ") AND "
How can I fix this error?

Many thanks in advance

Allen Browne said:
Okay, I think I must have missed your train of thought somewhere, so
have
just re-read this thread.

You have a text field named NombCom. You have a form with 5 unbound
check
boxes, representing 5 possible values in that field. You want to filter
this
form, so that any record that matches the value associated with any of
the
checked boxes gets included.

You'll need to build a filter string that looks like this:
NombCom IN ('Alfred','Betty','Charlene')

The code would look like this:

Dim strTmp As String
Dim lngLen As Long
strTmp = ""
If Me.CheckA.Value Then
strTmp = "'Alfred',"
End If
If Me.CheckB.Value Then
strTmp = strTmp & "'Betty',"
End If
'and so on to CheckE.
lngLen = Len(strTmp) - 1
If lngLen > 0 Then
strWhere = "NombCom IN (" & Left$(strTmp), lngLen) & ") AND "
End If
'and so on with the other filter options for your form.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.


Hello Allen
After reading your article, I see that my first table relationship
design
is
correct. That means I cannot use check box to filter records with my
correct
design?
My idea to use check boxes is to allow user to select one or more
checks
in
the form to filter records. For example filtering by two years and
two or
more. check boxes.
If check boxes is not good, how can I filter one or more fields in a
txtbox?

Thank you very much.

:

Yes, you will certainly have the problem of constantly having to
modify
your
table (and everything else that depends on it) when you use lots of
yes/no
fields like that.

Is there any chance I can talk you into using a correctly normalized
design
for your tables instead? See:
Don't use Yes/No fields to store preferences
at:
http://allenbrowne.com/casu-23.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.



Hello Allen
I have to modify my table (with the check box field) and then
linked to
the
realtions. I let you know if I success.
Thank you very much indeed.
:

Your quotes are not right.
You need to replace MyYesNofield with the name of your yes/no
field.

strWhere = strWhere & "(MyYesNofield = " & Nz(Me.chkA, False)
& "
AND
"

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.


message

Allen

I'm really confused, I know is my little skills in programming.
With this code:

If Not IsNull(Me.txtFilterAID) Then
strWhere = strWhere & "([AID] Like """ & Me.txtFilterID &
""")
AND "
End If

When I type a number in txtFilterAID and click the cmdFilter
the
form
shows
the records.The field AID is a string.

Nevertheless, with this code:
'If NotIsNull(Me.chkA) Then
'strWhere = strWhere & "(MyYesNofield = & Nz(Me.chkA, False)
&"
And
""
'End If

When I click the chkA and then click the cmdFilter codeVBA
displays
Compile
error: Sub or Function not defined.
The piece of code NotIsNull is selected in blue colour.

Could you tell me what I'm doing wrong? Please

What I'm trying to do is if I click in a check box (chkA) and
then
I
click
the cmdFilter the form will displays the filtered records in
the
form.

The table that I'm trying to filter records has the filed A
without
the
check box.
I hope my message is clear. I'm so sad due to my mother tongue
is
not
English.

Hoping to hear from you

:

You can append the true/false value of a check box into a
WHERE
string,
e.g.:
strWhere = strWhere & "(MyYesNoField = " & Nz(Me.Check1,
False)
&
")
AND
"

This doesn't allow you to leave it blank (so it doesn't filter
on
this
field.) An unbound check box can be null, but that's not very
visually
useful to the user. I think you're better using a combo box
where
the
user
can choose yes or no or leave it blank.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.


message

Allen.

I can see the check box in my table in DataSheet. Thank you
very
much
indeed.
Now. How can I use this check box in your search form?I have
been
using
your
search form example successfully.
In my form I have this code to filter using a txtbox and I
know
that
using
check box will allow user to check one or more check boxes

This is the code I'm using to search by txtbox:
Private Sub cmdFilter_Click()
Dim strWhere As String
Dim lngLen As Long

If Not IsNull(Me.txtFilterAID) Then
strWhere = strWhere & "([AID] = """ & Me.txtFilterAID &
""")
AND
"
End If

If Not IsNull(Me.txtFilterB) Then
strWhere = strWhere & "( Like ""*" & Me.txtFilterB &
""")
AND
"
End If

If Not IsNull(Me.txtFilterC) Then
strWhere = strWhere & "([C] Like ""*" & Me.txtFilterC &
""")
AND
"
End If

If Not IsNull(Me.txtFilterD) Then **** Here is where I need
to
search
using
the Check box***
strWhere = strWhere & "([D] Like ""*" & Me.txtFilterD &
""")
AND
"
End If

Many thanks.

:

Try entering the expression in the Immediate Window.

Press Ctrl+G to open the Immediate Window.
Substitute your table name for Table1, and your field name
for
Field1.
Have the table closed at the time you do this.
After you press Enter, you won't get any message unless
there is
an
error.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.


message
Hello
I have spent weeks trying to use Check boxes on my form
in
Access
2003.
I
received samples of code from this forum, but
unfortunately
I'm
still a
beginner in vba. My head aches but I hope this time I'll
be
lucky
and
I
can
use correctly you help.

In http://allenbrowne.com/NoYesNo.html web site. 'The
interface
does
not
offer Check Box as an option, but you can set the
property
programmatically
like this:

CurrentDb.TableDefs("Table1").Fields("Field1").Properties("DisplayControl")
=
CInt(acCheckBox)'.' Where in my table I can write this
code?

In my db MyTable has two fields ComID as PK (string) and
NombCom
as
string.
I would really appreciate if you can tell me step by step
how
to
write
the
code.

On the other hand, I have been using a textbox on a form
to
search
and
works
well

If Not IsNull(Me.txtComID) Then
strWhere = strWhere & "([ComID] Like """ & Me.txtComID &
""")
 
Allen

Many thanks againg for you kindness.
I declare de variable as String but the code does not work. I declare the
variable as Integer or Lon but displays error. I really dont know how to fix
my problem.

I have these references:

Visual Basic For Applications
Microsoft Access 11.0 Object Library
OLE Automation
Microsoft DAO 3.6 Object Library
Microsoft ActiveX Data Objects 2.5 Library

Thanks againg
Allen Browne said:
Declare the variable, and make sure you don't have any missing references:
http://allenbrowne.com/ser-38.html

Can't debug this for you.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.


sebastico said:
Allen

Many thanks for your kindness

I fix my error, however, vba displays in the same line of code: Compile
error:variable not defined and strWhere is coloured in blue.
The field NombComb in my table is Number. I have no idea how to fix this
error.
I really appreciated your help


sebastico said:
Allen
I apologize for delay in writing, my computer was out of the web for a
couple of weeks.
Trying your code vba displays this message: Compile error: Expected: end
of
statement.
Next line is coloured in yellow and the pointer in the , after (strTmp)
is
coloured in blue.
strWhere = "NombCom IN (" & Left$(strTmp), lngLen) & ") AND "
How can I fix this error?

Many thanks in advance

:

Okay, I think I must have missed your train of thought somewhere, so
have
just re-read this thread.

You have a text field named NombCom. You have a form with 5 unbound
check
boxes, representing 5 possible values in that field. You want to filter
this
form, so that any record that matches the value associated with any of
the
checked boxes gets included.

You'll need to build a filter string that looks like this:
NombCom IN ('Alfred','Betty','Charlene')

The code would look like this:

Dim strTmp As String
Dim lngLen As Long
strTmp = ""
If Me.CheckA.Value Then
strTmp = "'Alfred',"
End If
If Me.CheckB.Value Then
strTmp = strTmp & "'Betty',"
End If
'and so on to CheckE.
lngLen = Len(strTmp) - 1
If lngLen > 0 Then
strWhere = "NombCom IN (" & Left$(strTmp), lngLen) & ") AND "
End If
'and so on with the other filter options for your form.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.


Hello Allen
After reading your article, I see that my first table relationship
design
is
correct. That means I cannot use check box to filter records with my
correct
design?
My idea to use check boxes is to allow user to select one or more
checks
in
the form to filter records. For example filtering by two years and
two or
more. check boxes.
If check boxes is not good, how can I filter one or more fields in a
txtbox?

Thank you very much.

:

Yes, you will certainly have the problem of constantly having to
modify
your
table (and everything else that depends on it) when you use lots of
yes/no
fields like that.

Is there any chance I can talk you into using a correctly normalized
design
for your tables instead? See:
Don't use Yes/No fields to store preferences
at:
http://allenbrowne.com/casu-23.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.



Hello Allen
I have to modify my table (with the check box field) and then
linked to
the
realtions. I let you know if I success.
Thank you very much indeed.
:

Your quotes are not right.
You need to replace MyYesNofield with the name of your yes/no
field.

strWhere = strWhere & "(MyYesNofield = " & Nz(Me.chkA, False)
& "
AND
"

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.


message

Allen

I'm really confused, I know is my little skills in programming.
With this code:

If Not IsNull(Me.txtFilterAID) Then
strWhere = strWhere & "([AID] Like """ & Me.txtFilterID &
""")
AND "
End If

When I type a number in txtFilterAID and click the cmdFilter
the
form
shows
the records.The field AID is a string.

Nevertheless, with this code:
'If NotIsNull(Me.chkA) Then
'strWhere = strWhere & "(MyYesNofield = & Nz(Me.chkA, False)
&"
And
""
'End If

When I click the chkA and then click the cmdFilter codeVBA
displays
Compile
error: Sub or Function not defined.
The piece of code NotIsNull is selected in blue colour.

Could you tell me what I'm doing wrong? Please

What I'm trying to do is if I click in a check box (chkA) and
then
I
click
the cmdFilter the form will displays the filtered records in
the
form.

The table that I'm trying to filter records has the filed A
without
the
check box.
I hope my message is clear. I'm so sad due to my mother tongue
is
not
English.

Hoping to hear from you

:

You can append the true/false value of a check box into a
WHERE
string,
e.g.:
strWhere = strWhere & "(MyYesNoField = " & Nz(Me.Check1,
False)
&
")
AND
"

This doesn't allow you to leave it blank (so it doesn't filter
on
this
field.) An unbound check box can be null, but that's not very
visually
useful to the user. I think you're better using a combo box
where
the
user
can choose yes or no or leave it blank.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.


message

Allen.

I can see the check box in my table in DataSheet. Thank you
very
much
indeed.
Now. How can I use this check box in your search form?I have
been
using
your
search form example successfully.
In my form I have this code to filter using a txtbox and I
know
that
using
check box will allow user to check one or more check boxes

This is the code I'm using to search by txtbox:
Private Sub cmdFilter_Click()
Dim strWhere As String
Dim lngLen As Long

If Not IsNull(Me.txtFilterAID) Then
strWhere = strWhere & "([AID] = """ & Me.txtFilterAID &
""")
AND
"
End If

If Not IsNull(Me.txtFilterB) Then
strWhere = strWhere & "( Like ""*" & Me.txtFilterB &
""")
AND
"
End If

If Not IsNull(Me.txtFilterC) Then
strWhere = strWhere & "([C] Like ""*" & Me.txtFilterC &
""")
AND
"
End If

If Not IsNull(Me.txtFilterD) Then **** Here is where I need
to
search
using
the Check box***
strWhere = strWhere & "([D] Like ""*" & Me.txtFilterD &
""")
AND
"
End If

Many thanks.

:

Try entering the expression in the Immediate Window.

Press Ctrl+G to open the Immediate Window.
 
I’m happy to tell you I was able to run the code you recommended to filter
records in a form using txtboxes and checkbox controls.

The code for checkbox works well with these three tables:
TableOOB
OOBID txt (indexed as Primary Key)

Table FaOOB
FAOOBID txt
FAOOBID txt

Table OOBID txt
FAOOBID (indexed as Primary Key)


My form is continuous where I have the controls
Name chk
Control Source I leaved blank
Row source Table/Query

In the button click I have the Allen’s Browne Search Form:

Private Sub cmdFilter_Click()
Dim strWhere As String
Dim lngLen As Long
Dim strTmp As String

If Not IsNull(Me.txtStartYyear) Then 'If start year has a value then
strWhere = strWhere & "([Yyear] >= """ & (Me.txtStartYyear) & """)
AND " 'add a value
End If

If Not IsNull(Me.txtEndYyear) Then 'If start year has a value then
strWhere = strWhere & "([Yyear] <= """ & (Me.txtEndYyear) & """) AND
" 'add a value
End If

strTmp = ""

Here is the code for checkbox
If Me.chkBio.Value Then 'If chkBio has a value then
strTmp = "'1'," 'add value 1
End If

If Me.chkBIE.Value Then
strTmp = strTmp & "'2',"
End If

If Me.chkCons.Value Then
strTmp = strTmp & "'3',"
End If

If Me.chkDIS.Value Then
strTmp = strTmp & "'4',"
End If

lngLen = Len(strTmp) - 1
If lngLen > 0 Then
strWhere = "NobCom IN (" & Left$(strTmp, lngLen) & ") AND "
End If

lngLen = Len(strWhere) - 5
If lngLen <= 0 Then 'Nah: there was nothing in the string.
MsgBox "No criteria", vbInformation, "Nothing to do."
Else 'Yep: there is something there, so remove the " AND
" at the end.
strWhere = Left$(strWhere, lngLen)
'For debugging, remove the leading quote on the next line. Prints to
Immediate Window (Ctrl+G).
'Debug.Print strWhere

'Finally, apply the string as the form's Filter.
Me.Filter = strWhere
Me.FilterOn = True

End If

End Sub

Now I need to add two more tables to the query.

One table is to search by checkboxes as well. However, I’m facing this
problem. For example, when I click chkBio the filter displays 5 records. If I
add another table (and the required field) to the query clicking chkBio will
filter 10 records. Why?

Here are the checkboxes
If Me.chkCult.Value Then
strWhere = strWhere1 & "'CU',"
End If

If Me.chkGeob.Value Then
strWhere = strWhere1 & "'GB',"
End If

If Me.chkPolAdm.Value Then
strWhere = strWhere1 & "'PA',"
End If

lngLen = Len(strTmp) - 1
If lngLen > 0 Then
strWhere = "SistD IN (" & Left$(strTmp, lngLen) & ") AND "
End If

I have been trying to run the above code many times, but without success.


With the other table I need to search with a txtbox on the form. The user
will input words separated by AND or Or, I don’t know the best choice. All
words are stored in Tables TableOOB/TWrds. The design and relationship with
these tables are:.

TableOOB
OOBID txt (indexed as Primary Key)

Table WrdsOOB
FAOOBID txt
FAOOBID txt

Table OOBID txt
FAOOBID (indexed as Primary Key)

My form is continuous where I have the controls
Name chk
Control Source I leaved blank
Row source Table/Query

txtWrds

If Not IsNull(Me.txtWrds Then
strWhere = strWhere & "([WrdsNomb] Like ""*" & Me. Me.txtWrds & """) AND "
End If

Important

1. It is important to remember that all controls in the form are triggered
by the cmbFilter_Click.
2. All searching controls in the form are in Header. I suppose the Row
Source of the forms must included all tables involved (and results are
displayed in Details
3. I would like to displays records in another Form rather tan in Detail.
The reason is that in Heather are 22 controls (6 txtboxes, and 18 chkboxes).

Thank you in advance for you help. I hope this message is understandable


Allen Browne said:
Declare the variable, and make sure you don't have any missing references:
http://allenbrowne.com/ser-38.html

Can't debug this for you.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.


sebastico said:
Allen

Many thanks for your kindness

I fix my error, however, vba displays in the same line of code: Compile
error:variable not defined and strWhere is coloured in blue.
The field NombComb in my table is Number. I have no idea how to fix this
error.
I really appreciated your help


sebastico said:
Allen
I apologize for delay in writing, my computer was out of the web for a
couple of weeks.
Trying your code vba displays this message: Compile error: Expected: end
of
statement.
Next line is coloured in yellow and the pointer in the , after (strTmp)
is
coloured in blue.
strWhere = "NombCom IN (" & Left$(strTmp), lngLen) & ") AND "
How can I fix this error?

Many thanks in advance

:

Okay, I think I must have missed your train of thought somewhere, so
have
just re-read this thread.

You have a text field named NombCom. You have a form with 5 unbound
check
boxes, representing 5 possible values in that field. You want to filter
this
form, so that any record that matches the value associated with any of
the
checked boxes gets included.

You'll need to build a filter string that looks like this:
NombCom IN ('Alfred','Betty','Charlene')

The code would look like this:

Dim strTmp As String
Dim lngLen As Long
strTmp = ""
If Me.CheckA.Value Then
strTmp = "'Alfred',"
End If
If Me.CheckB.Value Then
strTmp = strTmp & "'Betty',"
End If
'and so on to CheckE.
lngLen = Len(strTmp) - 1
If lngLen > 0 Then
strWhere = "NombCom IN (" & Left$(strTmp), lngLen) & ") AND "
End If
'and so on with the other filter options for your form.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.


Hello Allen
After reading your article, I see that my first table relationship
design
is
correct. That means I cannot use check box to filter records with my
correct
design?
My idea to use check boxes is to allow user to select one or more
checks
in
the form to filter records. For example filtering by two years and
two or
more. check boxes.
If check boxes is not good, how can I filter one or more fields in a
txtbox?

Thank you very much.

:

Yes, you will certainly have the problem of constantly having to
modify
your
table (and everything else that depends on it) when you use lots of
yes/no
fields like that.

Is there any chance I can talk you into using a correctly normalized
design
for your tables instead? See:
Don't use Yes/No fields to store preferences
at:
http://allenbrowne.com/casu-23.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.



Hello Allen
I have to modify my table (with the check box field) and then
linked to
the
realtions. I let you know if I success.
Thank you very much indeed.
:

Your quotes are not right.
You need to replace MyYesNofield with the name of your yes/no
field.

strWhere = strWhere & "(MyYesNofield = " & Nz(Me.chkA, False)
& "
AND
"

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.


message

Allen

I'm really confused, I know is my little skills in programming.
With this code:

If Not IsNull(Me.txtFilterAID) Then
strWhere = strWhere & "([AID] Like """ & Me.txtFilterID &
""")
AND "
End If

When I type a number in txtFilterAID and click the cmdFilter
the
form
shows
the records.The field AID is a string.

Nevertheless, with this code:
'If NotIsNull(Me.chkA) Then
'strWhere = strWhere & "(MyYesNofield = & Nz(Me.chkA, False)
&"
And
""
'End If

When I click the chkA and then click the cmdFilter codeVBA
displays
Compile
error: Sub or Function not defined.
The piece of code NotIsNull is selected in blue colour.

Could you tell me what I'm doing wrong? Please

What I'm trying to do is if I click in a check box (chkA) and
then
I
click
the cmdFilter the form will displays the filtered records in
the
form.

The table that I'm trying to filter records has the filed A
without
the
check box.
I hope my message is clear. I'm so sad due to my mother tongue
is
not
English.

Hoping to hear from you

:

You can append the true/false value of a check box into a
WHERE
string,
e.g.:
strWhere = strWhere & "(MyYesNoField = " & Nz(Me.Check1,
False)
&
")
AND
"

This doesn't allow you to leave it blank (so it doesn't filter
on
this
field.) An unbound check box can be null, but that's not very
visually
useful to the user. I think you're better using a combo box
where
the
user
can choose yes or no or leave it blank.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.


message

Allen.

I can see the check box in my table in DataSheet. Thank you
very
much
indeed.
Now. How can I use this check box in your search form?I have
been
using
your
search form example successfully.
In my form I have this code to filter using a txtbox and I
know
that
using
check box will allow user to check one or more check boxes

This is the code I'm using to search by txtbox:
Private Sub cmdFilter_Click()
Dim strWhere As String
Dim lngLen As Long

If Not IsNull(Me.txtFilterAID) Then
strWhere = strWhere & "([AID] = """ & Me.txtFilterAID &
""")
AND
"
End If

If Not IsNull(Me.txtFilterB) Then
strWhere = strWhere & "( Like ""*" & Me.txtFilterB &
""")
AND
"
End If

If Not IsNull(Me.txtFilterC) Then
strWhere = strWhere & "([C] Like ""*" & Me.txtFilterC &
""")
AND
"
End If

If Not IsNull(Me.txtFilterD) Then **** Here is where I need
to
search
using
the Check box***
strWhere = strWhere & "([D] Like ""*" & Me.txtFilterD &
""")
AND
"
End If

Many thanks.

:

Try entering the expression in the Immediate Window.

Press Ctrl+G to open the Immediate Window.
 
sebastico said:
[snip]
One table is to search by checkboxes as well. However, I’m facing this
problem. For example, when I click chkBio the filter displays 5 records.
If I add another table (and the required field) to the query clicking
chkBio will filter 10 records. Why?

This is a new question. It has to do with the way queries work.

If you add Table2 to a query, and it has 2 records matching the one in
Table1, the query that previously output 1 record will now output two.
Hence, 5 records can become 10 when you add another table.
 
I’m happy to tell you I was able to run the code you recommended to filter
records in a continuous form using textboxes and checkbox controls.

The code for checkbox works well with these three tables:
TableOOB
OOBID txt (indexed as Primary Key) bounded to FAOOBID in Table FaOOB

Table FaOOB
FAOOBID txt
FAOOBID txt

Table OOBID txt
FAOOBID (indexed as Primary Key) bounded to FAOOBID in Table FaOOB


My form is continuous where I have the controls
Name chk
Control Source I leaved blank
Row source Table/Query

In the button click I have the Allen’s Browne Search Form:

Private Sub cmdFilter_Click()
Dim strWhere As String
Dim lngLen As Long
Dim strTmp As String
Filering by Start Year and End Year

If Not IsNull(Me.txtStartYyear) Then 'If start year has a value then
strWhere = strWhere & "([Yyear] >= """ & (Me.txtStartYyear) & """)
AND " 'add a value
End If

If Not IsNull(Me.txtEndYyear) Then 'If start year has a value then
strWhere = strWhere & "([Yyear] <= """ & (Me.txtEndYyear) & """) AND
" 'add a value
End If









Now this code filter by checkboxes
strTmp = ""

Here is the code for checkbox
If Me.chkBio.Value Then 'If chkBio has a value then
strTmp = "'1'," 'add value 1
End If

If Me.chkBIE.Value Then
strTmp = strTmp & "'2',"
End If

If Me.chkCons.Value Then
strTmp = strTmp & "'3',"
End If

If Me.chkDIS.Value Then
strTmp = strTmp & "'4',"
End If

lngLen = Len(strTmp) - 1
If lngLen > 0 Then
strWhere = "NobCom IN (" & Left$(strTmp, lngLen) & ") AND "
End If

lngLen = Len(strWhere) - 5
If lngLen <= 0 Then 'Nah: there was nothing in the string.
MsgBox "No criteria", vbInformation, "Nothing to do."
Else 'Yep: there is something there, so remove the " AND
" at the end.
strWhere = Left$(strWhere, lngLen)
'For debugging, remove the leading quote on the next line. Prints to
Immediate Window (Ctrl+G).
'Debug.Print strWhere

'Finally, apply the string as the form's Filter.
Me.Filter = strWhere
Me.FilterOn = True

End If

End Sub





Now I need to add two more tables to the query.

One table is to search by checkboxes as well. However, I’m facing this
problem. For example, when I click chkBio the filter displays 5 records. If I
add another table (and the required field) to the query clicking chkBio will
filter 10 records. Why?

Here are the checkboxes
If Me.chkCult.Value Then
strWhere = strWhere1 & "'CU',"
End If

If Me.chkGeob.Value Then
strWhere = strWhere1 & "'GB',"
End If

If Me.chkPolAdm.Value Then
strWhere = strWhere1 & "'PA',"
End If

lngLen = Len(strTmp) - 1
If lngLen > 0 Then
strWhere = "SistD IN (" & Left$(strTmp, lngLen) & ") AND "
End If

I have been trying to run the above code many times, but without success.


With the other table I need to search with a txtbox on the form. The user
will input words separated by AND or OR, I don’t know the best choice. All
words are stored in Tables TableOOB/TWrds. The design and relationship with
these tables are:.

TableOOB
OOBID txt (indexed as Primary Key)

Table WrdsOOB
FAOOBID txt
FAOOBID txt

Table OOBID txt
FAOOBID (indexed as Primary Key)


My form is continuous where I have the controls
Name chk
Control Source I leaved blank
Row source Table/Query
txtWrds

If Not IsNull(Me.txtWrds Then
strWhere = strWhere & "([WrdsNomb] Like ""*" & Me. Me.txtWrds & """) AND "
End If


Remarks

1. It is important to remember that all controls in the form must be
triggered by the cmbFilter_Click.
2. All searching controls in the form are in Header. I suppose the Row
Source of the forms must included all tables involved and all records founded
are displayed in Details
3. I would like to display records in another Form rather tan in Detail. The
reason is that in Header are 22 controls (6 textboxes, and 18 checkboxes).

Thank you in advance for you help. Since my mother tongue is no English I
hope this message is understandable

Allen Browne said:
Declare the variable, and make sure you don't have any missing references:
http://allenbrowne.com/ser-38.html

Can't debug this for you.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.


sebastico said:
Allen

Many thanks for your kindness

I fix my error, however, vba displays in the same line of code: Compile
error:variable not defined and strWhere is coloured in blue.
The field NombComb in my table is Number. I have no idea how to fix this
error.
I really appreciated your help


sebastico said:
Allen
I apologize for delay in writing, my computer was out of the web for a
couple of weeks.
Trying your code vba displays this message: Compile error: Expected: end
of
statement.
Next line is coloured in yellow and the pointer in the , after (strTmp)
is
coloured in blue.
strWhere = "NombCom IN (" & Left$(strTmp), lngLen) & ") AND "
How can I fix this error?

Many thanks in advance

:

Okay, I think I must have missed your train of thought somewhere, so
have
just re-read this thread.

You have a text field named NombCom. You have a form with 5 unbound
check
boxes, representing 5 possible values in that field. You want to filter
this
form, so that any record that matches the value associated with any of
the
checked boxes gets included.

You'll need to build a filter string that looks like this:
NombCom IN ('Alfred','Betty','Charlene')

The code would look like this:

Dim strTmp As String
Dim lngLen As Long
strTmp = ""
If Me.CheckA.Value Then
strTmp = "'Alfred',"
End If
If Me.CheckB.Value Then
strTmp = strTmp & "'Betty',"
End If
'and so on to CheckE.
lngLen = Len(strTmp) - 1
If lngLen > 0 Then
strWhere = "NombCom IN (" & Left$(strTmp), lngLen) & ") AND "
End If
'and so on with the other filter options for your form.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.


Hello Allen
After reading your article, I see that my first table relationship
design
is
correct. That means I cannot use check box to filter records with my
correct
design?
My idea to use check boxes is to allow user to select one or more
checks
in
the form to filter records. For example filtering by two years and
two or
more. check boxes.
If check boxes is not good, how can I filter one or more fields in a
txtbox?

Thank you very much.

:

Yes, you will certainly have the problem of constantly having to
modify
your
table (and everything else that depends on it) when you use lots of
yes/no
fields like that.

Is there any chance I can talk you into using a correctly normalized
design
for your tables instead? See:
Don't use Yes/No fields to store preferences
at:
http://allenbrowne.com/casu-23.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.



Hello Allen
I have to modify my table (with the check box field) and then
linked to
the
realtions. I let you know if I success.
Thank you very much indeed.
:

Your quotes are not right.
You need to replace MyYesNofield with the name of your yes/no
field.

strWhere = strWhere & "(MyYesNofield = " & Nz(Me.chkA, False)
& "
AND
"

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.


message

Allen

I'm really confused, I know is my little skills in programming.
With this code:

If Not IsNull(Me.txtFilterAID) Then
strWhere = strWhere & "([AID] Like """ & Me.txtFilterID &
""")
AND "
End If

When I type a number in txtFilterAID and click the cmdFilter
the
form
shows
the records.The field AID is a string.

Nevertheless, with this code:
'If NotIsNull(Me.chkA) Then
'strWhere = strWhere & "(MyYesNofield = & Nz(Me.chkA, False)
&"
And
""
'End If

When I click the chkA and then click the cmdFilter codeVBA
displays
Compile
error: Sub or Function not defined.
The piece of code NotIsNull is selected in blue colour.

Could you tell me what I'm doing wrong? Please

What I'm trying to do is if I click in a check box (chkA) and
then
I
click
the cmdFilter the form will displays the filtered records in
the
form.

The table that I'm trying to filter records has the filed A
without
the
check box.
I hope my message is clear. I'm so sad due to my mother tongue
is
not
English.

Hoping to hear from you

:

You can append the true/false value of a check box into a
WHERE
string,
e.g.:
strWhere = strWhere & "(MyYesNoField = " & Nz(Me.Check1,
False)
&
")
AND
"

This doesn't allow you to leave it blank (so it doesn't filter
on
this
field.) An unbound check box can be null, but that's not very
visually
useful to the user. I think you're better using a combo box
where
the
user
can choose yes or no or leave it blank.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.


message

Allen.

I can see the check box in my table in DataSheet. Thank you
very
much
indeed.
Now. How can I use this check box in your search form?I have
been
using
your
search form example successfully.
In my form I have this code to filter using a txtbox and I
know
that
using
check box will allow user to check one or more check boxes

This is the code I'm using to search by txtbox:
Private Sub cmdFilter_Click()
Dim strWhere As String
Dim lngLen As Long

If Not IsNull(Me.txtFilterAID) Then
strWhere = strWhere & "([AID] = """ & Me.txtFilterAID &
""")
AND
"
End If

If Not IsNull(Me.txtFilterB) Then
strWhere = strWhere & "( Like ""*" & Me.txtFilterB &
""")
AND
"
End If

If Not IsNull(Me.txtFilterC) Then
strWhere = strWhere & "([C] Like ""*" & Me.txtFilterC &
""")
AND
"
End If

If Not IsNull(Me.txtFilterD) Then **** Here is where I need
to
search
using
the Check box***
strWhere = strWhere & "([D] Like ""*" & Me.txtFilterD &
""")
AND
"
End If

Many thanks.

:

Try entering the expression in the Immediate Window.

Press Ctrl+G to open the Immediate Window.
 
Allen
Thank very much indeed for your kindness.

If I understand your message that means:
1. I can not enter data in txtboxes and in checkboxes at a time and then
click the filter to show the records founded
2. I can not use another set of check boxes to filter records from another
table.
3. How can I do to show the records in another form rather than in de Detail
section?
3. Or do I have to formulate a new questions to the forum?

Thanks again

Allen Browne said:
sebastico said:
[snip]
One table is to search by checkboxes as well. However, I’m facing this
problem. For example, when I click chkBio the filter displays 5 records.
If I add another table (and the required field) to the query clicking
chkBio will filter 10 records. Why?

This is a new question. It has to do with the way queries work.

If you add Table2 to a query, and it has 2 records matching the one in
Table1, the query that previously output 1 record will now output two.
Hence, 5 records can become 10 when you add another table.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

.
 
You lost me. I don't see how your question about entering data into text
boxes and check boxes relates to the problem of having too many records in
the recordset. Once you combine more tables in a query, it may become
read-only, but that's another problem again.

Perhaps you could post a new question.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.


sebastico said:
Allen
Thank very much indeed for your kindness.

If I understand your message that means:
1. I can not enter data in txtboxes and in checkboxes at a time and then
click the filter to show the records founded
2. I can not use another set of check boxes to filter records from another
table.
3. How can I do to show the records in another form rather than in de
Detail
section?
3. Or do I have to formulate a new questions to the forum?

Thanks again

Allen Browne said:
sebastico said:
[snip]
One table is to search by checkboxes as well. However, I’m facing this
problem. For example, when I click chkBio the filter displays 5
records.
If I add another table (and the required field) to the query clicking
chkBio will filter 10 records. Why?

This is a new question. It has to do with the way queries work.

If you add Table2 to a query, and it has 2 records matching the one in
Table1, the query that previously output 1 record will now output two.
Hence, 5 records can become 10 when you add another table.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

.
 
Back
Top