473,320 Members | 1,982 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Problem with VBA Filter function

Hello all.
Let me start by saying that I don't use VBA so often, so I ask for your
forgivness if my questions is somewhat silly.
I'm trying to find if a user typed the same value in two or more
controls in an unbound form. In order to do so, I moved the content of
the controls to an array (that was the easy part) and used the Filter
function in order to count the occurence of a each value. However, when
I ran the code I got the 450 error message: "Wrong number of arguments
or invalid property assignment" and the Filter word was highlighted.
After a bit of more trials, I wrote the simplest code:

Private Sub Button1_Click()
Dim StringArray(2) As String
Dim ResultArray() As String
Dim SearchString As String
Dim i As Integer

StringArray(0)="a"
StringArray(1)="b"
StringArray(2)="c"

SearchString="a"

ResultArray = Filter (StringArray,SearchString)
i = Ubound(ResultArray)-Lbound(ResultArray)+1
MsgBox i
End Sub

Still got the error. I tried to run the code both on Access 2K and
Access 2002. Same results.
I tried to use the other two argument in the Filter function - no use.
What am I doing wrong?

Apr 6 '06 #1
4 11020
<ha*****@bezeqint.net> wrote in message
news:11**********************@i39g2000cwa.googlegr oups.com...
Hello all.
Let me start by saying that I don't use VBA so often, so I ask for your
forgivness if my questions is somewhat silly.
I'm trying to find if a user typed the same value in two or more
controls in an unbound form. In order to do so, I moved the content of
the controls to an array (that was the easy part) and used the Filter
function in order to count the occurence of a each value. However, when
I ran the code I got the 450 error message: "Wrong number of arguments
or invalid property assignment" and the Filter word was highlighted.
After a bit of more trials, I wrote the simplest code:

Private Sub Button1_Click()
Dim StringArray(2) As String
Dim ResultArray() As String
Dim SearchString As String
Dim i As Integer

StringArray(0)="a"
StringArray(1)="b"
StringArray(2)="c"

SearchString="a"

ResultArray = Filter (StringArray,SearchString)
i = Ubound(ResultArray)-Lbound(ResultArray)+1
MsgBox i
End Sub

Still got the error. I tried to run the code both on Access 2K and
Access 2002. Same results.
I tried to use the other two argument in the Filter function - no use.
What am I doing wrong?

Because you have written the code in a form's module, there may be confusion
with the Filter property of the form. Try putting VBA.Filter to clearly
show you mean to use the Filter function from the VBA library.
Having said that, I don't know if this is how I would implement what you are
trying to achieve. Could you not simply loop through the controls on the
form by using the Me.Controls collection.
Apr 6 '06 #2
Anthony.
First, Many many thanks!!!
the VBA. prefix worked like a charm!

Second, your suggestion about looping through the controls is also good
and I used it as my first solution, but I had to ditch it since I need
to take only part of the controls and not all of them. At First, I
thought that I can't use a statement like Me.Controls(x).ControlType
(Thank you Microsoft so much for that UNDOCUMENTED feature). But after
your reply, I thought it over again and tried it. It worked!

Many thanks.

Apr 6 '06 #3
<ha*****@bezeqint.net> wrote in message
news:11**********************@u72g2000cwu.googlegr oups.com...
Anthony.
First, Many many thanks!!!
the VBA. prefix worked like a charm!

Second, your suggestion about looping through the controls is also good
and I used it as my first solution, but I had to ditch it since I need
to take only part of the controls and not all of them. At First, I
thought that I can't use a statement like Me.Controls(x).ControlType
(Thank you Microsoft so much for that UNDOCUMENTED feature). But after
your reply, I thought it over again and tried it. It worked!

Many thanks.

Great.
Thanks for the feedback.
Apr 6 '06 #4
ha*****@bezeqint.net wrote:
Anthony.
First, Many many thanks!!!
the VBA. prefix worked like a charm!

Second, your suggestion about looping through the controls is also good
and I used it as my first solution, but I had to ditch it since I need
to take only part of the controls and not all of them. At First, I
thought that I can't use a statement like Me.Controls(x).ControlType
(Thank you Microsoft so much for that UNDOCUMENTED feature). But after
your reply, I thought it over again and tried it. It worked!

Many thanks.

Sometimes you can put a value in the Tag property. That way you can
look through the controls...maybe test if its a text or combo, and look
at the tag. If it contains a value, say 1, then process, else ignore.
Apr 6 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Robin Cull | last post by:
Imagine I have a dict looking something like this: myDict = {"key 1": , "key 2": , "key 3": , "key 4": } That is, a set of keys which have a variable length list of associated values after...
45
by: Joh | last post by:
hello, i'm trying to understand how i could build following consecutive sets from a root one using generator : l = would like to produce : , , , ,
4
by: JP SIngh | last post by:
Thanks to Manohar for writing the basic code for displaying the managers and the employees in a tree like structure. I have adapted the code below but it gives me an error "exception occcured"...
3
by: jty202 | last post by:
I encounter a problem. I have three files: index.aspx index.aspx.vb HTMLContentParser.vb (doesn't have the class WebForm1 I put all three file in the same directory. when I ran...
1
by: tangus via DotNetMonster.com | last post by:
Hello all, I'm really struggling with getting some Active Directory code to work in ASP.NET. Can you please provide assistance? I am executing the following code: Dim enTry As DirectoryEntry =...
1
by: AlexW | last post by:
Hi I am in the process of developing an inventory application in visual basic. I keep coming up against a problem with using the dataview.rowfilter property. Basically what happens is this: -a...
2
osward
by: osward | last post by:
Hello there, I am using phpnuke 8.0 to build my website, knowing little on php programing. I am assembling a module for my member which is basically cut and paste existing code section of...
4
by: Gilberto | last post by:
Hello, I have a couple of forms using the code to FIND AS YOU TYPE from Allen Browne (http://allenbrowne.com/AppFindAsUType.html). It worked PERFECTLY until yesterday when i splitted the db into...
2
by: Shashank | last post by:
Hi, I am passing a tcpdump filter to a function which compiles the filter using pcap_compile and then sets it. Here is the filter, ip>=0x0000 and ip <=0xd9295a3 and ip >=0x0000 and ip...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.