Dear All,
I found this code snippet on this list (taken from a nice webpage of a
courteous fellow), which I used to filter a form on a combo box. I
wanted to repeat the same code to have an additional combo control
doing a different filtering on the same form, and simply copied the
code below and changed the appropriate combo names.
_______________ _______________ _______________ _________
Private Sub ExpByType_After Update()
If IsNull(Me.ExpBy Type) Then
Me.FilterOn = False
Else
Me.Filter = "TypeID = """ & Me.ExpByType & """"
Me.FilterOn = True
End If
End Sub
_______________ _______________ _______________ ___________
But the above code snippet gives me an error message:
"Run time error 2001: You cancelled the previous operation" and the
debug points to the line of:
" Me.Filter = "TypeID = """ & Me.ExpByType & """""
The strange thing is that I already have an other combo on that form
using the very similar code, working just fine...
Can anyone find what I am doing wrong and correct me?
Thanks in advance: Viktor 7 3361
By chance is the value of this new combo numeric? The code you have listed is for
searching for a text value. If the value is numeric, you'll need to remove some of the
quotes.
--
Wayne Morgan
"Vic" <la*****@ntlwor ld.com> wrote in message
news:52******** *************** ***@posting.goo gle.com... Dear All,
I found this code snippet on this list (taken from a nice webpage of a courteous fellow), which I used to filter a form on a combo box. I wanted to repeat the same code to have an additional combo control doing a different filtering on the same form, and simply copied the code below and changed the appropriate combo names. _______________ _______________ _______________ _________ Private Sub ExpByType_After Update() If IsNull(Me.ExpBy Type) Then Me.FilterOn = False Else Me.Filter = "TypeID = """ & Me.ExpByType & """" Me.FilterOn = True End If End Sub _______________ _______________ _______________ ___________
But the above code snippet gives me an error message:
"Run time error 2001: You cancelled the previous operation" and the debug points to the line of:
" Me.Filter = "TypeID = """ & Me.ExpByType & """""
The strange thing is that I already have an other combo on that form using the very similar code, working just fine...
Can anyone find what I am doing wrong and correct me?
Thanks in advance: Viktor
The message indicates that there is something wrong with the filter string
you are trying to assign.
If there is a space in the TypeID field's name, try:
Me.Filter = "[Type ID] = """ & Me.ExpByType & """"
If the TypeID is a Number type field, drop the extra quotes:
Me.Filter = "[TypeID] = " & Me.ExpByType
The other possibility is that the filter cannot be assigned, because the
record is dirty and cannot be saved. At the top of the procedure, add:
If Me.Dirty Then
Me.Dirty = False
End If
--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
"Vic" <la*****@ntlwor ld.com> wrote in message
news:52******** *************** ***@posting.goo gle.com... Dear All,
I found this code snippet on this list (taken from a nice webpage of a courteous fellow), which I used to filter a form on a combo box. I wanted to repeat the same code to have an additional combo control doing a different filtering on the same form, and simply copied the code below and changed the appropriate combo names. _______________ _______________ _______________ _________ Private Sub ExpByType_After Update() If IsNull(Me.ExpBy Type) Then Me.FilterOn = False Else Me.Filter = "TypeID = """ & Me.ExpByType & """" Me.FilterOn = True End If End Sub _______________ _______________ _______________ ___________
But the above code snippet gives me an error message:
"Run time error 2001: You cancelled the previous operation" and the debug points to the line of:
" Me.Filter = "TypeID = """ & Me.ExpByType & """""
The strange thing is that I already have an other combo on that form using the very similar code, working just fine...
Can anyone find what I am doing wrong and correct me?
Thanks in advance: Viktor
Thanks Allen, worked perfectly...The problem was as you predicted,
that TypeID was a number not a string, while the other combo which
worked nicely on the same form has a string primary key.
I am a novice access user, and could use another advice: how could I
have use this two combo and the code to filter for two criteria at the
same time? E.g. If TypeID is set to a certain type, and in the other
combo AuthorID is set to a specific Author, then I would like to
filter for those records which has the given author AND a certain
type...
Is this very complicated to do? I do not have a slightest idea how to
start,:-(
The other thing I wanted to understand: The filter string. What is the
"&" stand for? And what is the difference between the use of quotes
and non-qoutes?
Me.Filter = "[Type ID] = """ & Me.ExpByType & """"
Sorry for all this naive questions and thanks for your help again:
Viktor
"Allen Browne" <ab************ ***@bigpond.net .au> wrote in message news:<Ia******* *************@n ews-server.bigpond. net.au>... The message indicates that there is something wrong with the filter string you are trying to assign.
If there is a space in the TypeID field's name, try: Me.Filter = "[Type ID] = """ & Me.ExpByType & """" If the TypeID is a Number type field, drop the extra quotes: Me.Filter = "[TypeID] = " & Me.ExpByType
The other possibility is that the filter cannot be assigned, because the record is dirty and cannot be saved. At the top of the procedure, add: If Me.Dirty Then Me.Dirty = False End If
-- Allen Browne - Microsoft MVP. Perth, Western Australia. Tips for Access users - http://allenbrowne.com/tips.html
"Vic" <la*****@ntlwor ld.com> wrote in message news:52******** *************** ***@posting.goo gle.com... Dear All,
I found this code snippet on this list (taken from a nice webpage of a courteous fellow), which I used to filter a form on a combo box. I wanted to repeat the same code to have an additional combo control doing a different filtering on the same form, and simply copied the code below and changed the appropriate combo names. _______________ _______________ _______________ _________ Private Sub ExpByType_After Update() If IsNull(Me.ExpBy Type) Then Me.FilterOn = False Else Me.Filter = "TypeID = """ & Me.ExpByType & """" Me.FilterOn = True End If End Sub _______________ _______________ _______________ ___________
But the above code snippet gives me an error message:
"Run time error 2001: You cancelled the previous operation" and the debug points to the line of:
" Me.Filter = "TypeID = """ & Me.ExpByType & """""
The strange thing is that I already have an other combo on that form using the very similar code, working just fine...
Can anyone find what I am doing wrong and correct me?
Thanks in advance: Viktor
Strings require quotes, numbers do not. The reason for the multiple quotes is to tell
Access to place a quote in the result.
MyVariable = "My String"
result is My String
MyVariable = """My String"""
result is "My String"
Sometimes you will see people use single quotes inside the double quotes because it is
easier to read and accomplishes the same thing, to a point. The single quotes will work as
long as none of the data has an apostrophe in it, such as the last name O'Rielly.
The 3 quotes together are actually one quote and two quotes on the left and two quotes and
one quote on the right. The outside quotes are the ones you would normally use to delimit
the string. The pair of quotes inside them are what create the quotes being returned with
the string. In your example, number the quotes from 1 to 8, left to right.
#1 & 4 offset each other. 2 & 3 are the double that return the quote character.
# 5 & 8 offset each other and are around the string returned by 6 & 7 which results in a
quote character.
Another possibility here, which is sometimes easier to read, is to use the Chr() function.
Each character on the keyboard has a number called an ASCII number or ANSI number (the 2
are different). The Chr() function uses the ASCII number. The number for a " is 34. So you
could concatenate in a " using the function. That would change your line to
Me.Filter = "[Type ID] = " & Chr(34) & Me.ExpByType & Chr(34)
The ampersand (&) is a concatenation symbol. It means take the part on each side and join
them together. You will sometimes see + used instead of &. This will work if the values
are strings. If the values can be interpreted as numeric or Null, you may get some
unexpected results (although, these sometimes come in handy).
Yes, you can filter on more than one field.
Example:
Me.Filter = "[Type ID] = """ & Me.ExpByType & """ And [AuthorID] = " & Me.txtAuthorID
If AuthorID is a string then
Me.Filter = "[Type ID] = """ & Me.ExpByType & """ And [AuthorID] = """ & Me.txtAuthorID &
""""
You will find this "doubling up" in a lot of cases where the delimiter, in this case the
quote, is supposed to be returned in the final result.
--
Wayne Morgan
"Vic" <la*****@ntlwor ld.com> wrote in message
news:52******** *************** ***@posting.goo gle.com... Thanks Allen, worked perfectly...The problem was as you predicted, that TypeID was a number not a string, while the other combo which worked nicely on the same form has a string primary key.
I am a novice access user, and could use another advice: how could I have use this two combo and the code to filter for two criteria at the same time? E.g. If TypeID is set to a certain type, and in the other combo AuthorID is set to a specific Author, then I would like to filter for those records which has the given author AND a certain type...
Is this very complicated to do? I do not have a slightest idea how to start,:-(
The other thing I wanted to understand: The filter string. What is the "&" stand for? And what is the difference between the use of quotes and non-qoutes?
Me.Filter = "[Type ID] = """ & Me.ExpByType & """"
Text fields need quote marks around the data, e.g.:
[Surname] = "Jones"
Date fields need # around the data, e.g.:
[InvoiceDate] = #1/1/2003#
Number fields need no delimiter, e.g.:
[Amount] = 5.67
You are creating a string to use for the Filter.
The string must be in quotes. You therefore need:
"[Amount] = 5.67"
When you try to put the Surname in quotes, Access thinks it has reached the
end of the string when it reaches the quote mark before Jones. To let it
know that this is actually *part* of the string, the trick is to double them
up, i.e.:
"This ""word"" is in quotes"
so what you need is:
"[Surname] = ""Jones"""
The ampersand is for joining two string together (concatenating) , e.g.:
"This is the first part" & " and this is the rest."
so if you need to concatenate the name into the string:
"[Surname] = """ & "Jones" & """"
If the name is to be read from a text box, you need:
"[Surname] = """ & [MyTextBox] & """"
Hope that makes sense now.
--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
"Vic" <la*****@ntlwor ld.com> wrote in message
news:52******** *************** ***@posting.goo gle.com... Thanks Allen, worked perfectly...The problem was as you predicted, that TypeID was a number not a string, while the other combo which worked nicely on the same form has a string primary key.
I am a novice access user, and could use another advice: how could I have use this two combo and the code to filter for two criteria at the same time? E.g. If TypeID is set to a certain type, and in the other combo AuthorID is set to a specific Author, then I would like to filter for those records which has the given author AND a certain type...
Is this very complicated to do? I do not have a slightest idea how to start,:-(
The other thing I wanted to understand: The filter string. What is the "&" stand for? And what is the difference between the use of quotes and non-qoutes?
Me.Filter = "[Type ID] = """ & Me.ExpByType & """"
Sorry for all this naive questions and thanks for your help again:
Viktor
"Allen Browne" <ab************ ***@bigpond.net .au> wrote in message
news:<Ia******* *************@n ews-server.bigpond. net.au>... The message indicates that there is something wrong with the filter
string you are trying to assign.
If there is a space in the TypeID field's name, try: Me.Filter = "[Type ID] = """ & Me.ExpByType & """" If the TypeID is a Number type field, drop the extra quotes: Me.Filter = "[TypeID] = " & Me.ExpByType
The other possibility is that the filter cannot be assigned, because the record is dirty and cannot be saved. At the top of the procedure, add: If Me.Dirty Then Me.Dirty = False End If
-- Allen Browne - Microsoft MVP. Perth, Western Australia. Tips for Access users - http://allenbrowne.com/tips.html
"Vic" <la*****@ntlwor ld.com> wrote in message news:52******** *************** ***@posting.goo gle.com... Dear All,
I found this code snippet on this list (taken from a nice webpage of a courteous fellow), which I used to filter a form on a combo box. I wanted to repeat the same code to have an additional combo control doing a different filtering on the same form, and simply copied the code below and changed the appropriate combo names. _______________ _______________ _______________ _________ Private Sub ExpByType_After Update() If IsNull(Me.ExpBy Type) Then Me.FilterOn = False Else Me.Filter = "TypeID = """ & Me.ExpByType & """" Me.FilterOn = True End If End Sub _______________ _______________ _______________ ___________
But the above code snippet gives me an error message:
"Run time error 2001: You cancelled the previous operation" and the debug points to the line of:
" Me.Filter = "TypeID = """ & Me.ExpByType & """""
The strange thing is that I already have an other combo on that form using the very similar code, working just fine...
Can anyone find what I am doing wrong and correct me?
Thanks in advance: Viktor
Thanks Allen and Wayne,
It makes more sense now. One last shot:
So if you do
Me.filter= "[TypeID]=" & Me.ExpByType
Me.ExpByType is a number. How come you can concatenate a string with a
number? Why does not this cause a type mismatch?
Appreciate the detailed answer you gave to my previous qustions
Viktor
"Wayne Morgan" <co************ *************** @hotmail.com> wrote in message
news:KL******** *********@newss vr17.news.prodi gy.com... Strings require quotes, numbers do not. The reason for the multiple quotes
is to tell Access to place a quote in the result.
MyVariable = "My String" result is My String MyVariable = """My String""" result is "My String"
Sometimes you will see people use single quotes inside the double quotes
because it is easier to read and accomplishes the same thing, to a point. The single
quotes will work as long as none of the data has an apostrophe in it, such as the last name
O'Rielly. The 3 quotes together are actually one quote and two quotes on the left
and two quotes and one quote on the right. The outside quotes are the ones you would normally
use to delimit the string. The pair of quotes inside them are what create the quotes
being returned with the string. In your example, number the quotes from 1 to 8, left to right.
#1 & 4 offset each other. 2 & 3 are the double that return the quote
character. # 5 & 8 offset each other and are around the string returned by 6 & 7
which results in a quote character.
Another possibility here, which is sometimes easier to read, is to use the
Chr() function. Each character on the keyboard has a number called an ASCII number or ANSI
number (the 2 are different). The Chr() function uses the ASCII number. The number for a
" is 34. So you could concatenate in a " using the function. That would change your line
to Me.Filter = "[Type ID] = " & Chr(34) & Me.ExpByType & Chr(34)
The ampersand (&) is a concatenation symbol. It means take the part on eac
h side and join them together. You will sometimes see + used instead of &. This will work
if the values are strings. If the values can be interpreted as numeric or Null, you may
get some unexpected results (although, these sometimes come in handy).
Yes, you can filter on more than one field.
Example: Me.Filter = "[Type ID] = """ & Me.ExpByType & """ And [AuthorID] = " &
Me.txtAuthorID If AuthorID is a string then Me.Filter = "[Type ID] = """ & Me.ExpByType & """ And [AuthorID] = """ &
Me.txtAuthorID & """"
You will find this "doubling up" in a lot of cases where the delimiter, in
this case the quote, is supposed to be returned in the final result.
-- Wayne Morgan
"Vic" <la*****@ntlwor ld.com> wrote in message news:52******** *************** ***@posting.goo gle.com... Thanks Allen, worked perfectly...The problem was as you predicted, that TypeID was a number not a string, while the other combo which worked nicely on the same form has a string primary key.
I am a novice access user, and could use another advice: how could I have use this two combo and the code to filter for two criteria at the same time? E.g. If TypeID is set to a certain type, and in the other combo AuthorID is set to a specific Author, then I would like to filter for those records which has the given author AND a certain type...
Is this very complicated to do? I do not have a slightest idea how to start,:-(
The other thing I wanted to understand: The filter string. What is the "&" stand for? And what is the difference between the use of quotes and non-qoutes?
Me.Filter = "[Type ID] = """ & Me.ExpByType & """"
As an example, let's say the number is 23.
The filter has to read:
"[TypeID] = 23"
so you have to concatenate the number onto the end of your string to get
this result.
There is a problem if the number is Null. In this case, concatenating the
number onto the string results in:
"[TypeID] = "
which clearly is not going to work.
To prevent this problem, you might want to use:
Me.filter= "[TypeID]=" & Nz(Me.ExpByType , 0)
Glad it makes sense. That's what this group is about.
--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
"Viktor Lakics" <la*****@ntlwor ld.com> wrote in message
news:jd******** ************@ne wsfep2-win.server.ntli .net... Thanks Allen and Wayne,
It makes more sense now. One last shot:
So if you do Me.filter= "[TypeID]=" & Me.ExpByType
Me.ExpByType is a number. How come you can concatenate a string with a number? Why does not this cause a type mismatch?
Appreciate the detailed answer you gave to my previous qustions
Viktor "Wayne Morgan" <co************ *************** @hotmail.com> wrote in
message news:KL******** *********@newss vr17.news.prodi gy.com... Strings require quotes, numbers do not. The reason for the multiple
quotes is to tell Access to place a quote in the result.
MyVariable = "My String" result is My String MyVariable = """My String""" result is "My String"
Sometimes you will see people use single quotes inside the double quotes because it is easier to read and accomplishes the same thing, to a point. The single quotes will work as long as none of the data has an apostrophe in it, such as the last name O'Rielly. The 3 quotes together are actually one quote and two quotes on the left
and two quotes and one quote on the right. The outside quotes are the ones you would
normally use to delimit the string. The pair of quotes inside them are what create the quotes being returned with the string. In your example, number the quotes from 1 to 8, left to
right. #1 & 4 offset each other. 2 & 3 are the double that return the quote character. # 5 & 8 offset each other and are around the string returned by 6 & 7 which results in a quote character.
Another possibility here, which is sometimes easier to read, is to use
the Chr() function. Each character on the keyboard has a number called an ASCII number or
ANSI number (the 2 are different). The Chr() function uses the ASCII number. The number for
a " is 34. So you could concatenate in a " using the function. That would change your line to Me.Filter = "[Type ID] = " & Chr(34) & Me.ExpByType & Chr(34)
The ampersand (&) is a concatenation symbol. It means take the part on
eac h side and join them together. You will sometimes see + used instead of &. This will
work if the values are strings. If the values can be interpreted as numeric or Null, you
may get some unexpected results (although, these sometimes come in handy).
Yes, you can filter on more than one field.
Example: Me.Filter = "[Type ID] = """ & Me.ExpByType & """ And [AuthorID] = " & Me.txtAuthorID If AuthorID is a string then Me.Filter = "[Type ID] = """ & Me.ExpByType & """ And [AuthorID] = """ &
Me.txtAuthorID & """"
You will find this "doubling up" in a lot of cases where the delimiter,
in this case the quote, is supposed to be returned in the final result.
-- Wayne Morgan
"Vic" <la*****@ntlwor ld.com> wrote in message news:52******** *************** ***@posting.goo gle.com... Thanks Allen, worked perfectly...The problem was as you predicted, that TypeID was a number not a string, while the other combo which worked nicely on the same form has a string primary key.
I am a novice access user, and could use another advice: how could I have use this two combo and the code to filter for two criteria at the same time? E.g. If TypeID is set to a certain type, and in the other combo AuthorID is set to a specific Author, then I would like to filter for those records which has the given author AND a certain type...
Is this very complicated to do? I do not have a slightest idea how to start,:-(
The other thing I wanted to understand: The filter string. What is the "&" stand for? And what is the difference between the use of quotes and non-qoutes?
Me.Filter = "[Type ID] = """ & Me.ExpByType & """" This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Sarah Tanembaum |
last post by:
Beside its an opensource and supported by community, what's the fundamental
differences between PostgreSQL and those high-price commercial database (and
some are bloated such as Oracle) from software giant such as Microsoft SQL
Server, Oracle, and Sybase?
Is PostgreSQL reliable enough to be used for high-end commercial
application? Thanks
|
by: E. Robert Tisdale |
last post by:
What makes a good C/C++ programmer?
Would you be surprised if I told you that
it has almost nothing to do with your knowledge of C or C++?
There isn't much difference in productivity, for example,
between a C/C++ programmers with a few weeks of experience
and a C/C++ programmer with years of experience.
You don't really need to understand the subtle details
or use the obscure features of either language
|
by: typingcat |
last post by:
First of all, I'm an Asian and I need to input Japanese, Korean and so
on. I've tried many PHP IDEs today, but almost non of them supported
Unicode (UTF-8) file.
I've found that the only Unicode support IDEs are DreamWeaver 8 and
Zend PHP Studio.
DreamWeaver provides full support for Unicode. However, DreamWeaver is
a web editor rather than a PHP IDE. It only supports basic IntelliSense
(or code completion) and doesn't have anything...
|
by: WindAndWaves |
last post by:
Can anyone tell me what is wrong with the goto command. I noticed it is one
of those NEVER USE.
I can understand that it may lead to confusing code, but I often use it like
this:
is this wrong?????
Function x
select case z
|
by: Keith K |
last post by:
Having developed with VB since 1992, I am now VERY
interested in C#. I've written several applications with
C# and I do enjoy the language.
What C# Needs:
There are a few things that I do believe MSFT should do to
improve C#, however.
I know that in the "Whidbey" release of VS.NET currently
| |
by: Jason Huang |
last post by:
Hi,
Would someone explain the following coding more detail for me? What's the
( ) for?
CurrentText = (TextBox)e.Item.Cells.Controls;
Thanks.
Jason
|
by: GS |
last post by:
I got a combobox box that I load at load time. the Item and vales ended up
in reverse order of each other, what went wrong?
the database table has the following row
code value
ebay http://www.ebay.com
google http://www.google.com
yahoo http://www.yahoo.com
However in the drop down list
displayed value used
ebay http://www.yahoo.com
|
by: tjb |
last post by:
I often see code like this:
/// <summary>
/// Removes a node.
/// </summary>
/// <param name="node">The node to remove.</param>
public void RemoveNode(Node node) {
<...>
}
|
by: Pyenos |
last post by:
import cPickle, shelve
could someone tell me what things are wrong with my code?
class progress:
PROGRESS_TABLE_ACTIONS=
DEFAULT_PROGRESS_DATA_FILE="progress_data"
PROGRESS_OUTCOMES=
|
by: Daniel.C |
last post by:
Hello.
I just copied this code from my book with no modification :
#include <stdio.h>
/* count characters in input; 1st version */
main()
{
long nc;
nc = 0;
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |