Hi Alex,
You have a few options. The easiest option is to use VBA code like
this:
Private Sub Command1_Click( )
Dim DB As DAO.Database, QD As DAO.QueryDef
dim str1 As String
str1 = txt0
Set DB = CurrentDB
'--first get rid of query test1 if already exists
For Each qd In db.QueryDefs
If qd.Name = "test1" Then
db.QueryDefs.De lete qd.Name
Exit For
End If
Next
'--create new test1 query
Set QD = DB.CreateQueryD ef("test1")
QD.SQL = "SELECT " _
& "[total_installs].[Unité Administrative] " _
& "From total_installs, uachoisi " _
& "WHERE " _
& "[total_installs].[UnitéAdministra tive]='" & str1 & "'"
DoCmd.OpenQuery "test1"
End Sub
Here you have a form that is based on your table, and txt0 is a textbox
that is linked to the table and Command1 is a command button on the
form. You assign the value of txt0 to the variable str1 and use str1 in
your Sql Statement. When you click the button,
Your other option is to create a public function and a public variable
in a standard code module (not a class module). You assign a value to
the public variable. Place the public function in the sql code in the
Query window. The function will take the value of the variable:
Public globalStr1 As String
Public Function funcStr1() As String
funcStr1 = globalStr1
End Function
In the sql in your query add the function to the criteria section of
your query. Note: you have to include both parentheses ()
Field: [UnitéAdministra tive]
Criteria: funcStr1()
You can assign a value to the function from a command button on a form:
Private Sub Command1_Click( )
globalStr1 = "something"
DoCmd.OpenQuery "test1"
End Sub
With this second example, you don't have to delete the query everytime.
Rich
*** Sent via Developersdex
http://www.developersdex.com ***