473,405 Members | 2,349 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,405 software developers and data experts.

vba code for search boxes

Hello all!

I have stranded with a problem. I tried to search some data in a form but my vba code doesn't work. I have managed it with 2 search boxes but i need now to search with 5 boxes. I will show you my code and my form so you guys/girls can see what i am trying to do. Please i need your help =)

greetings Chiel (beginner in vba code)

*when you click on the button 'zoek' then it has to search for 1 of the 5 boxes.*

VBA code what doesn't work.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Knopzoekbetaling_Click()
  2.     If IsNull(tb_voorletters) And IsNull(tb_achternaam) _
  3.         And IsNull(tb_persoonnummerbetaling) And IsNull(tb_reserveringnr) Then
  4.         MsgBox "vul voorletters, achternaam, persoonnummer of reserveringnummer in", vbInformation, "zoeken"
  5.     Else
  6.         If Not IsNull(tb_voorletters) Then
  7.             Me.Filter = "voorletters like '" & tb_voorletters.Value & "*'"
  8.         Else
  9.             If Not IsNull(tb_tussenvoegsels) Then
  10.                 Me.Filter = "tussenvoegsels like '" & tb_tussenvoegsels.Value & "*'"
  11.             Else
  12.                 If Not IsNull(tb_voorletters) Then
  13.                     Me.Filter = "achternaam like '" & tb_achternaam.Value & "*'"
  14.                 Else
  15.                     If Not IsNull(tb_persoonnummerbetaling) Then
  16.                         Me.Filter = "persoonnummer = " & Me.persoonnummer.Value
  17.                     Else
  18.                         If Not IsNull(tb_reserveringnr) Then
  19.                             Me.Filter = "reserveringnummer = " & Me.reserveringnummer.Value
  20.                         Else
  21.                         End If
  22.                         Me.FilterOn = True
  23.                     End If
  24.                 End If
  25.             End If
  26.         End If
  27.     End If
  28. End Sub

Attached Images
File Type: jpg searchboxes.jpg (7.1 KB, 192 views)
Dec 23 '13 #1
6 1270
zmbd
5,501 Expert Mod 4TB
VBA code what doesn't work.
What about your code doesn't work?
Have you tried placeing a stop between lines 1 and 2 and then debug step thru to determine if your logic is happening as expected?

> We don't mind helping; however, we do ask that you do the basic troubleshooting first.
> Before Posting (VBA or SQL) Code

1) learning to step your code will help you follow your logic. I've done this for you in the posted code. Please use the [CODE/] button to format script and tables.

2) As it appears now, your filter doesn't get turned on unless the form at design has it turned on at default or unless you have a value for every on of your controls. So move Me.FilterOn = True from line 22 to just before the end sub.

3) Build your string first, then set it in the form's filter property. That way you can do a debug.print on the string to check if it's being built correctly.
Dec 23 '13 #2
Hello, thank you for helping me!

At first i wanted to say i am sorry for not using the [code/].

I have done step 2 and i also understand why that has to be done.
But i do not understand step 3. I dont know how to build a string. (I haven't learned that yet at school). Can you please show me a simple example so i can use that to understand it.

Also the thing what doesnt work on my vba code is the section below line 9. Then i can search on voorletters but when i add other code it says this error: 'compile error: method or data member not found'.

Again i appreciate your help!

Greetings Chiel

(i have already changed in line 12 the tb_voorletters to tb_achternaam, i saw this fault but fixed it. Still i get the error)
Dec 23 '13 #3
ADezii
8,834 Expert 8TB
If I am reading your Code cirrectly, you may want to restructure and simplify it, as in:
Expand|Select|Wrap|Line Numbers
  1. Dim strFilter As String
  2.  
  3. If IsNull(tb_voorletters) And IsNull(tb_achternaam) _
  4.         And IsNull(tb_persoonnummerbetaling) And IsNull(tb_reserveringnr) Then
  5.         MsgBox "vul voorletters, achternaam, persoonnummer of reserveringnummer in", _
  6.         vbInformation, "zoeken"
  7. ElseIf Not IsNull(tb_voorletters) Then
  8.   strFilter = "voorletters like '" & tb_voorletters.Value & "*'"
  9. ElseIf Not IsNull(tb_tussenvoegsels) Then
  10.   strFilter = "tussenvoegsels like '" & tb_tussenvoegsels.Value & "*'"
  11. ElseIf Not IsNull(tb_voorletters) Then
  12.   strFilter = "achternaam like '" & tb_achternaam.Value & "*'"
  13. ElseIf Not IsNull(tb_persoonnummerbetaling) Then
  14.   strFilter = "persoonnummer = " & Me.persoonnummer.Value
  15. ElseIf Not IsNull(tb_reserveringnr) Then
  16.   strFilter = "reserveringnummer = " & Me.reserveringnummer.Value
  17. Else
  18.   'escape hatch
  19. End If
  20.  
  21. If strFilter = "" Then Exit Sub
  22.  
  23. With Me
  24.   .Filter = strFilter
  25.   .FilterOn = True
  26. End If
Dec 23 '13 #4
Thank you, but i still get the same error: compile error: method or data member not found. =/
Dec 23 '13 #5
zmbd
5,501 Expert Mod 4TB
line 9: "tb_tussenvoegsels"
The error is telling you that this is not in the recordset or is not a control on the form, double check the spelling.
Dec 23 '13 #6
Ok i found a spelling error. Thank you for saying that.
I also found that the with had to close with a end with. Also the last end if had to go.

But now it works!

I will thanks you both guys, I really appreciate the time you took for my problem!

Greetings, Chiel
Dec 23 '13 #7

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

Similar topics

0
by: Huihong | last post by:
Please check out our source code search engine here, http://www.codase.com e.g., search main method,...
8
by: Steph | last post by:
Hi. I'm very new to MS Access and have been presented with an Access database of contacts by my employer. I am trying to redesign the main form of the database so that a button entitled...
13
by: sembiance | last post by:
Hi folks :) I've been working on a C/C++ Source Code search engine website for over a year now, and just thought I'd let you all know that I just put it live a few minutes ago. It searches 99...
8
by: Huihong | last post by:
Please check out our newly released source code search engine here, http://www.codase.com e.g., search socket method call,...
0
by: Huihong | last post by:
Please check out our source code search engine here, http://www.codase.com e.g., search the "main" method,...
1
by: jamesmoore | last post by:
Hi I have two search boxes with one submit button I want one search box to search one table in my database and the other search box to search another table in my database Then If there is a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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

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