Question : Sending a Criteria "Like [!A-Z]" from a form to a query

I have a simple form that is used to filter the results of a query, if the user selects "A" then the result of the query comes out with all products starting with "A", and so on...
I noticed that the LIKE operator needs to be typed in the query and the form will send A* (I use select case, CASE "A" then myvariable = "A*"). I am trying to send a criteria that selects non alphabets , numbers and other characters, but for some reason the query generates empty rows when I send [!A-Z]  (CASE "Other" myvariable = "[!A-Z]", and again i can not send the LIKE operator from the form.
Any ideas how can I pull names starting with other characters than alphabets by using the Like operator.

thanks

Answer : Sending a Criteria "Like [!A-Z]" from a form to a query

hi,

Can't you use in your query:

like forms![FormName]![ControlName]*

Big disadvantage is that you need to have your form open when you run the query.

Another thing you can do is to rebuild your query everytime a user presses the button.

Sub cmdRunQuery_Click()

      Dim MyDatabase As DATABASE
      Dim MyQueryDef As QueryDef
      Dim where As Variant

      Set MyDatabase = CurrentDb()

On Error GoTo read
        MyDatabase.QueryDefs.Delete "Name"
        MyDatabase.QueryDefs.Refresh
read:

    where = Null
    where = where & " AND [Field] like Me![Conrol]+ "*'"
   
   
Set MyQueryDef = MyDatabase.CreateQueryDef("Name", _
        "Select * TabelName " & (" where " + Mid(where, 6) & ";"))

fcco

Random Solutions  
 
programming4us programming4us