Query - criteria

hafiff

Board Regular
Joined
Feb 5, 2008
Messages
65
Hi everyone,

I a query setup and the criteria is pulled from a form, frmReport_1

on query, I entered: Like [Forms]![frmReport_1].[loc]

On the frmReport_1, I have a combo box with a value list of Not 3;"All";1;"Non-Provisional";2;"Provisional"

When I entered as "All", the report is blank - no reports. The rest options work fine. Does anyone know how to produce report without the number 3; thus, only number 1 and 2 will show.

Thanks,
HA
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Change the Criteria in the Query to:

Code:
choose([COLOR=#333333][Forms]![frmReport_1].[loc][/COLOR],"IN(1)","IN(2)","IN(1,2)")
 
Upvote 0
Here is a VBA based solution. The Code runs on the Combobox After_Update Event procedure. Modifies the SQL definition of the SELECT Query based on the selection in the Combobox.

Code:
Private Sub Combo4_AfterUpdate()
Dim strSQL As String, crit As String, cboval As Integer
Dim qryDef As QueryDef, db As Database, crit2 As String


Set db = CurrentDb
Set qryDef = db.QueryDefs("Query45")


strSQL = "SELECT Table1.* From Table1 WHERE (((Jobs.IDX)="

crit2 = "));"


cboval = Me!Combo4
If cboval = 1 Then
  crit = "1"
ElseIf cboval = 2 Then
  crit = "2"
Else
  crit = "1 OR (Jobs.IDX)=2"
End If


qryDef.SQL = strSQL & crit & crit2
db.QueryDefs.Refresh


End Sub
 
Upvote 0

Forum statistics

Threads
1,214,833
Messages
6,121,861
Members
449,052
Latest member
Fuddy_Duddy

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top