Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2013
    Posts
    6

    Unanswered: Access function return wildcard character

    Hi,
    I am working in Access. I have a combobox that gets its row source from a query. next to it is a togglebutton.

    In a table, I have a field called 'ID' that only stores numeric data.

    The query for the combobox has three fields, one of which is 'ID'. I need to set this up so that if the togglebutton is off, the criteria for the ID field is '10', but if the togglebutton is on, the criteria for the 'ID' field is all numbers, which I am guessing is "*".

    I have added a function for the 'ID' field criteria, but when I run it, when the toggle button is 'off', I get the correct results, but when it is 'on' (searching for "*") I get nothing. I do have the combobox.requery working.

    My function looks like this: (togAdministrator is my toggle button)

    Function ReturnIDNumber()
    If Forms.frmclassdetails.togAdministrator.Value = -1 Then
    ReturnIDNumber = "*"
    Else
    ReturnIDNumber = 10
    End If
    End Function

    Can anyone help me and tell me what I am doing wrong?

    Thanks!

  2. #2
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    The WHERE clause of the query should be something like:
    Code:
    WHERE CStr([ID]) Like ReturnIDNumber()
    While the function should be:
    Code:
    Function ReturnIDNumber() As String
    
        If Forms.frmclassdetails.togAdministrator.Value = True Then
            ReturnIDNumber = "*"
        Else
            ReturnIDNumber = "10"
        End If
        
    End Function
    Have a nice day!

  3. #3
    Join Date
    Jul 2013
    Posts
    6
    That sorted it! Many thanks!

  4. #4
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    You're welcome!
    Have a nice day!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •