Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Function to return Like " * " 1

Status
Not open for further replies.

dmon000

Technical User
Joined
Sep 9, 2003
Messages
79
Location
US
The first If in this function works fine.
The second If does not work. I know I'm doing something wrong. How does one correctly write W = LIKE " * "?

Thanks !!

Public Function rptWho() As String

Dim w As String

If Not IsNull(Forms!fNP_300a_REPORTS.Combo23) Then
w = Forms!fNP_300a_REPORTS.Combo23
End If

If IsNull(Forms!fNP_300a_REPORTS.Combo23) Then
w = Like " * "
End If

rptWho = w

w = vbNullString

End Function
 





Hi,

LIKE is an operator, used in this manner...
Code:
If [i]variable[/i] LIKE "*XYZ*" Then...
w = Like " * " is not correct syntax.

What are you trying to do?


Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
if w is suppose to be a used in a query statement then you could try w = "Like ""*"""

ck1999
 


ck1999,

What kind of query statement has w [red]=[/red] Like anything???


Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 


ck1999,

What kind of query statement has w [red]=[/red] Like anything???

I suppose it could be...
Code:
Where w = "Like ""*"""
or something similar to that, where the litteral Like is a value.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Clearly dmon000 needs to provide some context to what he/she is attempting to accomplish. It would certainly avoid lots of WAGs and prevent us from wasting time when we don't know the true question/issue.

Duane
Hook'D on Access
MS Access MVP
 

I suspect dmon000 is trying to use his function to obtain the where clause in a query. If so, something like this should do the trick...
Code:
Public Function OptMask()
    Dim frm As Form, opt As OptionGroup
    Set frm = Forms!frmReports
    Set opt = frm!fraFacility
    Select Case opt.Value
        Case 1:
            OptMask = 1
        Case 2:
            OptMask = 2
        Case Else:
            [COLOR=red]OptMask = "*"[/color]
    End Select
    Set opt = Nothing
    Set frm = Nothing
End Function
This code gets the value from a text box on the form, but you can modify it to suit your purpose. The part I think you're having problems with is in red.

Randy
 
SkipVought,

I was thinking maybe he was trying to set the w to what we wanted in the query statement.

such as

Where fldstuff = w


This was just a thought from how I read his post.
 
Ladies and Gentleman:
I apologize for not giving you enough information.

I was trying to use the rptWho() function as a criteria in a query. I was hoping that this code:
If IsNull(Forms!fNP_300a_REPORTS.Combo23) Then
w = Like " * "
End If

would place this in the query criteria box: Like "*", which would then return all records.
The first IF in the function above returns a user's name. I wanted to provide an option to get the records for all users names.

Once again, My apologies.

dmon000 (Dave)
 
In the criteria cell of your query, replace this:
=rptWho()
with this:
=Forms!fNP_300a_REPORTS!Combo23 OR Forms!fNP_300a_REPORTS!Combo23 Is Null

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Take the Like statement out of your function and put it in the query. Your function still looks pretty much the same:

Public Function rptWho() As String

Dim w As String

If Not IsNull(Forms!fNP_300a_REPORTS.Combo23) Then
w = Forms!fNP_300a_REPORTS.Combo23
End If

If IsNull(Forms!fNP_300a_REPORTS.Combo23) Then
w = " * " <------------TAKE OUT LIKE STATEMENT

End If

rptWho = w

w = vbNullString

End Function
*****************************************

In your query's criteria box stick in:

Like rptWho()

It will return the single value exactly as argued if there are no wildcard operators in the argument, like you have in

If Not IsNull(Forms!fNP_300a_REPORTS.Combo23) Then
w = Forms!fNP_300a_REPORTS.Combo23
End If

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top