code wild card value for form variable

G

Guest

i use a check box in an option group to generate a specific value for a
variable.
using the following code

If Forms![fee sched form]![select region] = 2 Then
Forms![fee sched form]![region var] = "Roch"
End If
If Forms![fee sched form]![select region] = 3 Then
Forms![fee sched form]![region var] = "CNY"
End If

this variable is hidden on the form and value is used a query.

how do i code this, so i can put "*" in the variable and thereby get all
values in the query?

the query code generates like "*" but i do not know how to code via the
forms command

thanks for your help
 
G

Guest

You can set the text box to Null, and then in the query add the criteria

Select * From TableName Where FieldName = Forms![fee sched form]![region
var] Or Forms![fee sched form]![region var] Is Null

So if the value is null the query will return all records

=============
Also, instead of using a hidden object in the form with code you can set the
criteria in the query

Select * From TableName Where FieldName Like IIf(Forms![fee sched
form]![select region]=2,"Roch",IIf(Forms![fee sched form]![select
region]=3,"CNY","*"))
 
M

Marshall Barton

jnewl said:
i use a check box in an option group to generate a specific value for a
variable.
using the following code

If Forms![fee sched form]![select region] = 2 Then
Forms![fee sched form]![region var] = "Roch"
End If
If Forms![fee sched form]![select region] = 3 Then
Forms![fee sched form]![region var] = "CNY"
End If

this variable is hidden on the form and value is used a query.

how do i code this, so i can put "*" in the variable and thereby get all
values in the query?

the query code generates like "*" but i do not know how to code via the
forms command


You didn'r say what condition(s?) indicates that * should be
used. Whatever it is, just use the same kind of thing that
you already have:

If somecondition Then
Forms![fee sched form]![region var] = "*"
End If

Set the field's criteria to:
Like Forms![fee sched form]![region var]
 
G

Guest

tried that before sending. what happens the quote marks get dropped, when
the value is stored in the variable. so instead of "*", you get *. the query
does not understand like *, so as a result get nothing.

so tried using a variable called quote and set that equal to "

then did region var = "like " & quote & "*" & quote.

got the same result of like *



Marshall Barton said:
jnewl said:
i use a check box in an option group to generate a specific value for a
variable.
using the following code

If Forms![fee sched form]![select region] = 2 Then
Forms![fee sched form]![region var] = "Roch"
End If
If Forms![fee sched form]![select region] = 3 Then
Forms![fee sched form]![region var] = "CNY"
End If

this variable is hidden on the form and value is used a query.

how do i code this, so i can put "*" in the variable and thereby get all
values in the query?

the query code generates like "*" but i do not know how to code via the
forms command


You didn'r say what condition(s?) indicates that * should be
used. Whatever it is, just use the same kind of thing that
you already have:

If somecondition Then
Forms![fee sched form]![region var] = "*"
End If

Set the field's criteria to:
Like Forms![fee sched form]![region var]
 
M

Marshall Barton

My mistake. Let's try setting the query criteria to

Like """" & Forms![fee sched form]![region var] & """"
--
Marsh
MVP [MS Access]

tried that before sending. what happens the quote marks get dropped, when
the value is stored in the variable. so instead of "*", you get *. the query
does not understand like *, so as a result get nothing.


Marshall Barton said:
jnewl said:
i use a check box in an option group to generate a specific value for a
variable.
using the following code

If Forms![fee sched form]![select region] = 2 Then
Forms![fee sched form]![region var] = "Roch"
End If
If Forms![fee sched form]![select region] = 3 Then
Forms![fee sched form]![region var] = "CNY"
End If

this variable is hidden on the form and value is used a query.

how do i code this, so i can put "*" in the variable and thereby get all
values in the query?

the query code generates like "*" but i do not know how to code via the
forms command


You didn'r say what condition(s?) indicates that * should be
used. Whatever it is, just use the same kind of thing that
you already have:

If somecondition Then
Forms![fee sched form]![region var] = "*"
End If

Set the field's criteria to:
Like Forms![fee sched form]![region var]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top