PC Review


Reply
Thread Tools Rate Thread

RE: Search criteria

 
 
Daryl S
Guest
Posts: n/a
 
      10th Feb 2010
Tony -

Is this what you want?

If isnull(txtsearch2) Then
Me.RecordSource = "SELECT * FROM [qrysearchHV] WHERE [txtcompany]like
""*" & _
Me.txtsearch.Value & "*""
Else
If isnull(txtsearch) Then
Me.RecordSource = "SELECT * FROM [qrysearchHV] WHERE [txtmonth] like
""*" & _
Me.txtsearch2.Value & "*"""
Else

Me.RecordSource = "SELECT * FROM [qrysearchHV] WHERE
[txtcompany]like ""*" & _
Me.txtsearch.Value & "*"" AND [txtmonth] like ""*" & _
Me.txtsearch2.Value & "*"""
End If
End If



--
Daryl S


"TonyWilliams via AccessMonster.com" wrote:

> I have a search form that selects records from a query when the value of two
> fields (txtmonth-a date field and txtcompnay- a text field) in the query
> match the value of two controls (txtsearch and txtsearch2) on my form.
> However I want to change the code so that the serach criteria works like this:
>
> Find records where:
> txtsearch=txtcompany and txtsearch2 is blank
> txtsearch2=txtmonth and txtsearch is blank
> txtsearch=txtcompany AND txtsearch2=txtmonth
>
> Here is my current code:
> Private Sub txtSearch_KeyPress(KeyAscii As Integer)
> If KeyAscii = 13 Then
> 'execute search
> ' Turn Off Screen Display while macros run
> DoCmd.Echo False, "Please wait while the search takes place "
> ' Turns on hourglass while macro runs
> DoCmd.Hourglass True
> ' Turns warning off so you don't answer prompt while macro runs
> DoCmd.SetWarnings False
>
> Debug.Print "Search for " & Me.txtsearch.Value
> Debug.Print "Search for " & Me.txtsearch2.Value
> Me.RecordSource = "SELECT * FROM [qrysearchHV] WHERE [txtcompany]
> like ""*" & Me.txtsearch.Value & "*"" AND [txtmonth] like ""*" & Me.
> txtsearch2.Value & "*"""
>
> Me.btnShowAll.Visible = True
> 'Me.lblSearch.Visible = False
> If Me.RecordsetClone.RecordCount = 0 Then
> Me.RecordSource = "qrysearchHV"
> Me.txtsearch.SetFocus
> Me.btnShowAll.Visible = False
> MsgBox "No records found for your search criteria", vbInformation,
> strAppName
> 'Me.lblSearch.Visible = True
> End If
> End If
> ' Turns off hourglass
> DoCmd.Hourglass False
> ' Turns warnings back on
> DoCmd.SetWarnings True
> ' Activates Screen display again
> DoCmd.Echo True, ""
> End Sub
>
> Can someone give me a steer on how I can change the code to achieve this?
> Thanks
> Tony
>
> --
> Why don't my grey cells communicate with each as fast as they used to? I hate
> getting old!
>
> Message posted via AccessMonster.com
> http://www.accessmonster.com/Uwe/For...oding/201002/1
>
> .
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Excel XP VBA code to search all macro code in Excel module for specific search string criteria Ed Microsoft Excel Programming 6 17th Aug 2012 04:46 PM
Search folder criteria - how to use "OR" criteria Melissa Microsoft Outlook Discussion 1 4th May 2010 07:24 PM
Multiple Criteria Search (5+ Search Fields) =?Utf-8?B?VE9NSA==?= Microsoft Access Database Table Design 3 30th May 2006 02:33 AM
How do I search excel spreadsheets using multiple search criteria. =?Utf-8?B?S2FzcGVy?= Microsoft Excel Worksheet Functions 4 15th Dec 2005 01:26 AM
Re: Excel XP VBA code to search all macro code in Excel module for specific search string criteria Frank Kabel Microsoft Excel Programming 0 19th May 2004 08:11 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:36 AM.