Microsoft Access Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMicrosoft Access Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old November 19th, 2004, 02:19 PM
Ericed Ericed is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 6 Ericed User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question Parameter query using comparison operators as variables.

I'm looking for help on a solution to use comparison operators (<, >, <>, <=, and >=, =) as variables in a query for a report. What I'm doing presently is using a form with combo boxes to select criteria for a SQL string to query a report.
I would like to add the capability to also choose(cmbobox) an operator and compare it to a number entered into a text box; Adding this comparison to the SQL String for the query.

If anybody has a solution or a better way of doing it, I would appreciate it greatly.

I'm presently using the code:

Private Sub cmdSetFilter_Click()
Dim strSQL As String, intCounter As Integer
'Build SQL String
For intCounter = 1 To 6
If Me("Filter" & intCounter) <> "" Then
strSQL = strSQL & "[" & Me("Filter" & intCounter).TAG & "] " & _
" = " & Chr(34) & Me("Filter" & intCounter) & Chr(34) & " And "
End If
Next

If strSQL <> "" Then
'Strip Last " And "
strSQL = Left(strSQL, (Len(strSQL) - 5))
'Set the Filter property
Reports![Assets Query].Filter = strSQL
Reports![Assets Query].FilterOn = True
Else
Reports![Assets Query].FilterOn = False
End If
End Sub

Reply With Quote
  #2  
Old November 20th, 2004, 08:40 PM
lwells lwells is offline
Contributing User
Dev Articles Novice (500 - 999 posts)
 
Join Date: Sep 2004
Posts: 632 lwells User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 21 h 59 m 38 sec
Reputation Power: 5
Ericed

Try this

Dim varOper As Variant

varOper = [OperatorComboBox]

strSQL = strSQL & "[" & Me("Filter" & intCounter).TAG & "] " & _
varOper & Chr(34) & Me("Filter" & intCounter) & Chr(34) & " And "

lwells

Reply With Quote
  #3  
Old November 23rd, 2004, 09:31 AM
John Ransom John Ransom is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 4 John Ransom User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Quote:
Originally Posted by Ericed
I'm looking for help on a solution to use comparison operators (<, >, <>, <=, and >=, =) as variables in a query for a report. What I'm doing presently is using a form with combo boxes to select criteria for a SQL string to query a report.
I would like to add the capability to also choose(cmbobox) an operator and compare it to a number entered into a text box; Adding this comparison to the SQL String for the query.

If anybody has a solution or a better way of doing it, I would appreciate it greatly.

I'm presently using the code:

Private Sub cmdSetFilter_Click()
Dim strSQL As String, intCounter As Integer
'Build SQL String
For intCounter = 1 To 6
If Me("Filter" & intCounter) <> "" Then
strSQL = strSQL & "[" & Me("Filter" & intCounter).TAG & "] " & _
" = " & Chr(34) & Me("Filter" & intCounter) & Chr(34) & " And "
End If
Next

If strSQL <> "" Then
'Strip Last " And "
strSQL = Left(strSQL, (Len(strSQL) - 5))
'Set the Filter property
Reports![Assets Query].Filter = strSQL
Reports![Assets Query].FilterOn = True
Else
Reports![Assets Query].FilterOn = False
End If
End Sub

I have 20 combo boxes and i typed in the same SQL text as you to get a filter based on the report but i could only get it work for one combo box. How did you get yours to work on all of your combo boxes? I would be grateful of any help, thanks.

Reply With Quote
  #4  
Old November 24th, 2004, 01:17 PM
Ericed Ericed is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 6 Ericed User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Microsoft has an example of this feature that I used at:

http://support.microsoft.com/kb/q208529/

It explains everything, and also has a link to the sample database "RptSmp00.mdb" along with other examples on how use reports.

Reply With Quote
  #5  
Old November 24th, 2004, 01:58 PM
Ericed Ericed is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 6 Ericed User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Quote:
Originally Posted by lwells
Ericed

Try this

Dim varOper As Variant

varOper = [OperatorComboBox]

strSQL = strSQL & "[" & Me("Filter" & intCounter).TAG & "] " & _
varOper & Chr(34) & Me("Filter" & intCounter) & Chr(34) & " And "

lwells


I have thought of using "varOper" like variable entrys in the SQL string, but since a string is continuously added to the prior string I end up with a faulty statement and data.

What I mean by this is; if I want to filter multiple cmbox's with filter criteria like:

= Department
= Name
>= CPU

I end up with for my SQL String is:

>= Department
>= Name
>= CPU

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMicrosoft Access Development > Parameter query using comparison operators as variables.


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT