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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with function in a query

Status
Not open for further replies.

48Highlander

Technical User
Feb 8, 2004
119
CA
I have the following function call in a query:
Code:
Prospect:flagcheck("GA",[Flags])
('Flags' is one of the fields in the table I am querying.)

Flagcheck is a public function with type Boolean.

I want to select records where the value of this function is 'True.' If I don't enteria the criteria of 'True,' the query displays the correct values of flagcheck. However, when I set the criteria to True or False (or a number) I am getting a data type mismatch error.

Anyone any clues? Want me to post the function?

Bill J
 
Heres the code for the function:

Code:
Public Function FlagCheck(strFlag, strFlagField As String) As Boolean

'   Used in queries to see if a particular flag has been set
    FlagCheck = False
    
    Dim strTemp As String
    Dim i, n, varLen As Integer
    Dim nFlags As Integer
    
    varLen = Len(Nz(strFlagField, ""))
    If varLen = 0 Then
        'No flags have been entered for this name
        Exit Function
    Else
        nFlags = (varLen + 1) / 4
    End If
    
    i = 1
    n = 1
    Do Until i = nFlags + 1
        
        If i = 1 Then
            strTemp = Left(strFlagField, 2)
        Else
            strTemp = Mid(strFlagField, n, 2)
        End If
        
        If strFlag = strTemp Then
            FlagCheck = True
            Exit Function
        End If
        
        n = n + 4
        i = i + 1
    
    Loop
    
        
Exit_ErrorHandler:
    Exit Function

Err_ErrorHandler:
    MsgBox "Error in 'CheckFlag' function" & vbCrLf & Err.Number & "  " & Err.Description
    Resume Exit_ErrorHandler
    
End Function

Bill J
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top