Wildcards

ddrew

seasoned user
Local time
Today, 10:50
Joined
Jan 26, 2003
Messages
911
Im trying to sort out a wildcard problem that keeps creating a type mismatch.

Code:
    If IsNull(Me.Breed) Then
        MsgBox "|Please choose an odour type", vbOKOnly
        Me.btn_Cadaver.SetFocus
    End If
    I[COLOR="Red"]f Me.Breed = "Cadaver (" * ")" Then[/COLOR]
        Me.Breed.SelStart = 9
    Else
        If Me.Breed = "Drugs (" * ")" Then
            Me.Breed.SelStart = 7
        Else
            If Me.Breed = "Explosives (" * ")" Then
                Me.Breed.SelStart = 12
            Else
                If Me.Breed = "Money (" * ")" Then
                    Me.Breed.SelStart = 7
                End If
            End If
        End If
    End If
End Sub
The error occurs on the line in red.
 
THere ya go lol.
 
What value do you actually have in the Me.Breed control? Is it double quoted? If yes, that is your problem !
 
Code:
If Me.Breed LIKE "Cadaver (*)" Then
Thanks you, what about if I wanted to search for a wildcard after my brackets
I thought that
Code:
If Me.Breed Like "Cadaver ()*"
might work but doesn't!
 
In simple terms what is that you are trying to do here?
 
Well that's because there are none with just an empty Cadaver () value in the brackets. Maybe Cadaver (*)*
 
Thanks you, what about if I wanted to search for a wildcard after my brackets
Like pr2-eugin I'm also confused. What do you mean by "search for a wildcard"?

Do you want to:
* test if some field begins with "Cadaver ()"
OR
* test if a field contains an asterisk (*)?
 
I'm basically trying to prevent anything being written outside of the brackets. The phrase "Cadaver () is put in the textbox automatically I want the user to be able to add text between the brackets.

From the comments it would appear that I'm going about this the wrong way.
 
Code:
    If IsNull(Me.Breed) Then
        MsgBox "|Please choose an odour type", vbOKOnly
        Me.btn_Cadaver.SetFocus
    End If

    If Me.Breed LIKE "Cadaver (*)" Then
        Me.Breed.SelStart = 9
    ElseIf Me.Breed LIKE "Drugs (*)" Then
        Me.Breed.SelStart = 7
    ElseIf Me.Breed LIKE "Explosives (*)" Then
        Me.Breed.SelStart = 12
    ElseIf Me.Breed LIKE "Money (*)" Then
        Me.Breed.SelStart = 7
    Else: MsgBox "Invalid Input"
    End If
 
IDEA:
Have two labels on either side of your text box and assign the left one Cadaver ( and the right one )

When retrieving the input join the values together with the text box.
 
IDEA:
Have two labels on either side of your text box and assign the left one Cadaver ( and the right one )

When retrieving the input join the values together with the text box.
Just what I was about to suggest, but in place of a label use a Locked texbox. Just so that you can set it's Control Source instead using the Caption property.
 
Code:
    If IsNull(Me.Breed) Then
        MsgBox "|Please choose an odour type", vbOKOnly
        Me.btn_Cadaver.SetFocus
    End If

    If Me.Breed LIKE "Cadaver (*)" Then
        Me.Breed.SelStart = 9
    ElseIf Me.Breed LIKE "Drugs (*)" Then
        Me.Breed.SelStart = 7
    ElseIf Me.Breed LIKE "Explosives (*)" Then
        Me.Breed.SelStart = 12
    ElseIf Me.Breed LIKE "Money (*)" Then
        Me.Breed.SelStart = 7
    Else: MsgBox "Invalid Input"
    End If

What event should this be put on please?
PS Thanks for your patience!
 
You're asking me? I just tidied the code you gave us and applied the fixes we have gone through. Put it back where you had it lol.
 
By the way, you want to put the second block of code in the ELSE part of the first block.
 
You're asking me? I just tidied the code you gave us and applied the fixes we have gone through. Put it back where you had it lol.

I just put it in the on change event and it didn't work, hence my asking!
 

Users who are viewing this thread

Back
Top Bottom