473,804 Members | 3,272 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Search multiple fields simultaneously for values within a certain range

13 New Member
Hi there, I'm returning to this forum for the second time and I would like to say thanks for the great help provided. I've encountered a new problem now and hope that you will be able to help me again.

I'm currently implementing a container monitoring system in MSAccess07 and I'm using a multiple search function to sort containers. I use several unbound text boxes and a list box.The user type's in partial search criteria in one or several text boxes. Or if they don't key in anything it returns all records. The matches are returned in a listbox.

I will show the code for 1 text box just to show how it works.

This is the code for the search button:

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdShowCont_Click()
  2. Dim MySQL As String, mycriteria As String, MyRecordSource As String
  3. Dim argcount As Integer
  4. Dim Tmp As Variant
  5. mycriteria = " "
  6. argcount = 0
  7. MySQL = "SELECT * FROM qryContLife  WHERE "
  8.  
  9. Addwtf [textbox], "[Arrival Date]", mycriteria, argcount, "textbox"
  10.  
  11. Debug.Print mycriteria
  12. If mycriteria = " " Then
  13. mycriteria = "True"
  14. End If
  15.  
  16. MyRecordSource = MySQL & mycriteria
  17. Me![listbox].RowSource = MyRecordSource
  18. If Me![listbox].ListCount = 0 Then
  19. MsgBox " There are no containers with this criteria. Sorry ", 48
  20. Me!cmdClear.SetFocus
  21. Else
  22. Me![listbox].SetFocus
  23. End If
  24.  
  25. End Sub
  26.  
This is the code for the sub which builds the SQL statement and through which the values are returned to the listbox:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Addwtf(fieldvalue As Variant, fieldname As String, mycriteria As String, argcount As Integer, fieldo As String)
  2. Dim wtf1 As String, wtf2, wtf3 As String
  3.  
  4.  If fieldvalue <> "" Then
  5.  If argcount > 0 Then
  6.      mycriteria = mycriteria & " and "
  7.  
  8.  End If
  9.  
  10.  Select Case fieldo
  11.  
  12. Case "textbox"
  13.        wtf2 = Mid$(fieldvalue, 4, 2) & "/" & Mid$(fieldvalue, 1, 2) & "/" & Mid$(fieldvalue, 7, 4)
  14.        mycriteria = (mycriteria & fieldname & " = " & Chr(35) & wtf2 & Chr(35))
  15.  
  16.   argcount = argcount + 1
  17.  End If
  18. End Sub
  19.  
The question is whether it is possible to make the search not for a specific date like the "Arrival Date" in this case (e.g. 01/12/2008) but for a specified range of dates like all values between 01/12/2008 and 01/01/2009. So that the code returns not just one value but all values in a specified range.

I hope I explained everything in a clear matter, if not please ask questions and I will try and make it more clear.

Thank you for spending your time of somebody else's problems.
Best regards, Eugene.
Jul 8 '08
10 3978
Eugenio
13 New Member
Expand|Select|Wrap|Line Numbers
  1. If IsDate(Me![txtBeginDate]) And IsDate(Me![txtEndDate]) Then
  2.    If CDate(Me![txtBeginDate]) < CDate(Me![txtEndDate]) Then
  3.       mycriteria = mycriteria _
  4.         & " AND [BirthDate] Between #" _
  5.         & Format(Me![txtBeginDate], "yyyy/mm/dd") _
  6.         & "# And #" _
  7.         & Format(Me![txtEndDate], "yyyy/mm/dd") & "# "
  8.    End If
  9. End If
  10.  
  11.  
Like this ? I cannot manage to retrieve the data to the listbox in this way though.
Jul 11 '08 #11

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

Similar topics

16
3074
by: Dixie | last post by:
I have a problem using Dev Ashish's excellent module to concatenate the results of a field from several records into one record. I am using the code to concatenate certain awards onto a certificate at the end of the year. I have the code working fine, except for the fact that when I want to restrict the entries to awards between certain dates, even though I can use the restriction in the query that shows the actual records, when the...
32
14917
by: tshad | last post by:
Can you do a search for more that one string in another string? Something like: someString.IndexOf("something1","something2","something3",0) or would you have to do something like: if ((someString.IndexOf("something1",0) >= 0) || ((someString.IndexOf("something2",0) >= 0) ||
5
5059
by: vonclausowitz | last post by:
Repost from an VB group. Hi All, I'm looking for a way to search for multiple words in a database. There is however one but. The words have to be within a certain range of each other. For example I would like to find records which contain the word MALE and within for example 10 words of it the word BROWN.
23
9077
blyxx86
by: blyxx86 | last post by:
I am trying to filter multiple entries with only one search box. That way the user can type whatever they want and find all the values that contain what they enter. Private Sub txtLookup_AfterUpdate() Me.Filter = " Like '*" & & "*'" OR " Like '*" & & "*'" Me.FilterOn = True End Sub It allows for variables and to filter within the form. I can't seem to find a way to make it actually search through multiple fields (Serial,...
2
3675
by: Kosmos | last post by:
Alright so I've got this Outlook code written in VBA in Access. The first part, which works, records information about appointment times based on the required days before notification of certain contracts and then it adds them to the outlook calendar of the current user. This code works and is nested within a bunch of if statements because it only needs to trap certain appointments. The table I create with this code is later used to attempt to...
1
1885
by: Rama Jayapal | last post by:
hi i am developing a web application where i have to read multiple XML feeds amd store their values to database but i require the same type of fields from multiple XML feeds like for example
14
2142
by: Thurston Manson | last post by:
Suppose I'm using an implementation where an int is 16 bits. In the program below, what function is called in the first case, and what is called in the second case? Also, if there is a difference between C89 and C99, I would like to know. I have tried with different compilers, and I see some differences. Before I file a bug report with my C vendor, I would like to know what the correct behavior is. struct S { unsigned a:4;
8
1143
by: Miro | last post by:
Hi sorry for the quick question. I am on the right track but just cant seem to find what to search for in my books / online for the answer I am looking for. I have created a dataset within my project. In the dataset I created 2 tables - and set some fields on the tables. In each table I set one of the fields to be a primary key / unique auto incremenet. So now I create a form, add a datagrid view to it and add to the dataset.
1
4746
by: annemariearmour | last post by:
I am using Crystal reports version 11.2 to create reports. The data source is SQL Server, and I am using views rather than reporting directly from tables. I apply selection criteria to the incoming records at record level and at group level. For example, I may select all bill lines with a receipt date within a certain date range. This results in a list of bill lines within that date range. The records are grouped and values on the records...
0
9708
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10589
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10327
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6857
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();...
0
5527
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5663
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4302
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
2
3828
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2999
bsmnconsultancy
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...

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.