"or" creteria in select query

ootkhopdi

Registered User.
Local time
Tomorrow, 04:44
Joined
Oct 17, 2013
Messages
181
i m a begeinner in access
pls tell me
how can set creteria in select query as
Textbox1 or textbox 2

textbox 1 and textbox 2 are field on diffrent forms

some time it may be on same form
pls tell me
 
In Query Design View:
First Criteria row: Forms!FormName!Textbox1
Second Criteria row: Forms!FormName!Textbox2

 
Dear Mihail
first thanks for your suggestion
i think my question is not clear
i want minimum requirement of both criteria
i want to use first textbox1 ,but if textbox1 is blank or not selected then value of textbox2 is use as criteria
 
Why have you designed a Query to include criteria from two different forms? If one of the Form is closed, the Query will pop up requesting the parameter value from you.. If you do want to get from two different forms, I think you need to go down the route of Dynamic Queries..
 
Here's what I do quite commonly if the criteria for a query can't really be known until runtime . . .
Code:
Function GetQueryText() As String
   Const BASE_SQL as string = _
      "SELECT * " & _
      "FROM Table "
   Dim Where As String
   
[COLOR="Green"]   'construct a where clause using two fields on a form[/COLOR]
   If Not IsNull(Me.Text0) Then Where = "And Field1 = " & Me.Text0
   If Not IsNull(Me.Text2) Then Where = Where & "And Field2 = " & Me.Text2
   If Where <> "" Then Where = "WHERE " & Mid(Where, 5)

   [COLOR="Green"]'construct and return the whole SQL[/COLOR]
   GetQueryText = BASE_SQL & Where
End Function
. . . so see how in this case if both textboxes are null, there is simply no where clause, and the query will return all the records.
 

Users who are viewing this thread

Back
Top Bottom