Convert Number to String

jamesWP

Registered User.
Local time
Today, 22:50
Joined
Aug 8, 2005
Messages
68
Hi there, on my form I'm using a drop down filter kind of thing, where you choose a field, then in the next combo box you choose a value, click filter and it then filters it all for you, the problem is, I have different data types, where as
Code:
"Name = '" &  combo21 & "'" 'Combo 21 will return a value such as "/dsfads/"
will work
Code:
"ID = '" &  combo21 & "'" 'In this instance it will hold a number such as 3
will not. Is there any way to force combo21 to always act as if its holding plain old text?

Thanks,
James Prince :)
 
Code:
Private Sub Label33_Click()
On Error Resume Next
Me.FilterOn = True
Combo27.SetFocus
Me.Filter = Combo25.Value & " = '" & CStr(Combo27.Text) & "'"
'Combo25.Value would be "Part No"
'Combo27.Value would be "001"
End Sub

Doesn't seem to work :S
 
Debug.print returns
Code:
Part No = '001'
to the immediate window, I just don't see what's wrong with it :S

Code:
Size = '12.7/22.0/M6'
Works just fine
 
To start with, I think you need to tell your code where these combo boxes are when you refer to them:

Me.Filter = me!Combo25.Value & " = '" & CStr(me!Combo27.Text) & "'"
 
When I try applying the filter using mine or your code, it takes absolutely no effect :S
 
Maybe:

Private Sub Label33_Click()
On Error Resume Next
Me.FilterOn = True
Combo27.SetFocus
Me.Filter = "'" & me!Combo25.Value & " = '" & CStr(Combo27.Text) & "''"
'Combo25.Value would be "Part No"
'Combo27.Value would be "001"
End Sub
 
Mmmm, that one lost me the little functuallity I had to begin with :P, what characters do you wrap numbers with? I know you wrap strings with ' '.
 
Here's where it seems you need to be (as a sample):

me.filter = "myfldName = 'SomeValue'"

So I was trying to put quotes around everthing...
 
Ok. don't despair :)

Does it work when you do this:

Me.Filter = "[Part No] = '001'"

???
 
Yup :o, Surpised I forgot to try that in the first place :$.
 
OK, now I'm a little confused. I was just trying to start from scratch to help fix your problem but after your last response it appears as though the problem has been resolved. True or false?

:confused:
 
Nope, only works if I hard code the values as you suggested, trying to grab them from the combobox doesn't work if it's a number :confused: .
 
so what does
debug.print Me.Filter = "'" & me!Combo25.Value & " = '" & CStr(Combo27.Text) & "''" return?

Peter
 
Ok - Try something like:

Code:
dim MyFilterString as string
MyFilterString = me!combo25 & "'" & me!combo27 & "'"
me.filter = MyFilterString

???
 
debug.print Me.Filter = "'" & me!Combo25.Value & " = '" & CStr(Combo27.Text) & "''"
returns
False
 
Code:
Private Sub Label33_Click()
On Error goto err_trap
Me.FilterOn = True
Dim MyFilterString As String
Combo27.SetFocus
MyFilterString = Combo25.Value & " = '" & CStr(Combo27.Text) & "'"
Me.Filter = MyFilterString
err_trap:
debug.print err.description
End Sub

After adding the error trapping, I was able to discover what the error is when the combo box shows a number,
Code:
Syntax error (missing operator) in query expression 'Part No = '012''.
 
Yay fixed it!

Thanks for the help Ken, if anyone else is interested the correct code was

Code:
Private Sub Label33_Click()
On Error GoTo err_trap
Me.FilterOn = True
Dim MyFilterString As String
Combo27.SetFocus
MyFilterString = "[" & Combo25.Value & "] = '" & CStr(Combo27.Text) & "'"
Me.Filter = MyFilterString
err_trap:
Debug.Print Err.Description
End Sub
 
Cool... Another reason not to use spaces in fld or object names :)
 

Users who are viewing this thread

Back
Top Bottom