Nov 25th, 2005, 11:02 AM
#1
Thread Starter
Frenzied Member
SQL Problem
Hi to all:
I have been a problem with SQL when I try to order the database (ACCESS),by name like:
João
António
I Think the problem it was with (ã) and (ó)...and my question is:
This is normal?Which way can I resolve this?
Thanks
Nov 25th, 2005, 11:39 AM
#2
Re: SQL Problem
It is normal I'm afraid, and the problem is the accented characters.
The reason this happens is because they are not seen as letters, but other ascii characters (just as - and £ would be). As sorting is done by ascii code, this provides odd results.
I'm afraid I dont know of a way to deal with it nicely, all I can think of is to have an extra column in the database which is a copy of the first, but without the accents. Alternatively you could replace the accented characters with their non-accented version in the Order By clause.
Nov 25th, 2005, 12:26 PM
#3
Thread Starter
Frenzied Member
Re: SQL Problem
Alternatively you could replace the accented characters with their non-accented version in the Order By clause.
And can you tell me the way I can do this,because this is my code in order Clause:
VB Code:
Private Sub Option1_Click(Index As Integer)
Dim aSQL As String
aSQL = "Select * from exposicao "
If Index = 1 Then aSQL = aSQL & " ORDER BY registo"
If Index = 2 Then aSQL = aSQL & " ORDER BY expositor"
If Index = 3 Then aSQL = aSQL & " ORDER BY n_socio"
If Index = 4 Then aSQL = aSQL & " ORDER BY stamfpo"
If Index = 5 Then aSQL = aSQL & " ORDER BY stamfocip"
If Index = 6 Then aSQL = aSQL & " ORDER BY nomesocio"
Set rsexposicao = db.OpenRecordset(aSQL)
Set Data1.Recordset = rsexposicao
End Sub
Thanks
Nov 25th, 2005, 12:42 PM
#4
Re: SQL Problem
Do you have a question about this? This would be a little quicker, as only one condition would execute. Each IF statement would be evaluated in your code.
VB Code:
Option Explicit
Private Sub Option1_Click(Index As Integer)
Dim aSQL As String
aSQL = "Select * from exposicao "
Select Case Index
Case Is = 1
aSQL = aSQL & " ORDER BY registo"
Case Is = 2
aSQL = aSQL & " ORDER BY expositor"
Case Is = 3
aSQL = aSQL & " ORDER BY n_socio"
Case Is = 4
aSQL = aSQL & " ORDER BY stamfpo"
Case Is = 5
aSQL = aSQL & " ORDER BY stamfocip"
Case Is = 6
aSQL = aSQL & " ORDER BY nomesocio"
End Select
Set rsexposicao = db.OpenRecordset(aSQL)
Set Data1.Recordset = rsexposicao
End Sub
Nov 25th, 2005, 06:32 PM
#5
Thread Starter
Frenzied Member
Re: SQL Problem
This is the other code I have for find a name:
VB Code:
Private Sub Text2_Change()
Dim aSQL, Letra As String
Letra = Text2.Text & "*"
aSQL = "Select * from exposicao "
If Option1(1).Value = True Then
aSQL = aSQL & "Where registo Like '" & Letra & "' Order By registo "
End If
If Option1(2).Value = True Then
aSQL = aSQL & "Where expositor Like '" & Letra & "' Order By expositor "
End If
Set rsexposicao = db.OpenRecordset(aSQL)
Set Data1.Recordset = rsexposicao
Grelha
mostrar
End Sub
if I put for example in the box text2 "João" The VB returns a error!
Any way to resolve this?
Thanks
Nov 26th, 2005, 01:14 PM
#6
Re: SQL Problem
What I meant was something like this:
Code:
Order By Replace(Replace(registo,'ã','a'),'ó','o') "
Note that the syntax you use to replace will vary by DBMS. (I think this will work for Access).
I have no idea why you get an error using Like, what is the error that is shown, and when does it get displayed (whcih line of code)?
Nov 27th, 2005, 08:56 AM
#7
Thread Starter
Frenzied Member
Re: SQL Problem
This is the line a get the error:
Run time error 3420
VB Code:
Set rsexposicao = db.OpenRecordset(aSQL)
I agree with you...I don't now why I have thie error...very strange
Thanks
Nov 27th, 2005, 05:17 PM
#8
Re: SQL Problem
I don't know the meaning of all the error codes, so you might like to let us know what the message is too
It would also be useful to know what the value of aSQL is at the time, so put this just before it:
..and post the SQL that is printed to the Immediate window (press Ctrl-G if it isn't visible).
Nov 28th, 2005, 04:50 AM
#9
Thread Starter
Frenzied Member
Re: SQL Problem
This is the message when I get the error:
Select * from exposicao Where nomesocio Like 'jo*' Order By nomesocio
Nov 28th, 2005, 07:24 AM
#10
Re: SQL Problem
You gave us the error number but what is the error message?
Nov 28th, 2005, 09:51 AM
#11
Thread Starter
Frenzied Member
Re: SQL Problem
The error is:
Error 3420
"Object invalid or no longer set"
Nov 28th, 2005, 11:18 AM
#12
Fanatic Member
Re: SQL Problem
Originally Posted by
sacramento
This is the message when I get the error:
Select * from exposicao Where nomesocio Like 'jo*' Order By nomesocio
Its definately the accented letter a thats doing it. Try the replace line in the above section. That MIGHT do it. Or... Repace the accented letters in the column names.
Good luck
Nov 28th, 2005, 11:51 AM
#13
Re: SQL Problem
Or, create a new column without the characters in it, so you could also return the accented character field. I think the LIKE statement doesn't like accented characters.
Nov 28th, 2005, 12:23 PM
#14
Thread Starter
Frenzied Member
Re: SQL Problem
but create a column without accented it's not a easy way no? or not?
because this must be do when I save all the fields in the column and make a copy to that column...not a easy way no?????
Nov 28th, 2005, 12:38 PM
#15
Re: SQL Problem
Can you find a field if you don't use Like? That way we'd know if it is a problem with Access (which might be able to be changed) or the LIKE statement (which likely can't be if we can't change Access.
Nov 28th, 2005, 01:08 PM
#16
Re: SQL Problem
Originally Posted by
sacramento
The error is:
Error 3420
"Object invalid or no longer set"
That sounds as if the db object is no longer valid, have you closed it somewhere else?
Nov 29th, 2005, 05:13 AM
#17
Thread Starter
Frenzied Member
Re: SQL Problem
Hi guys:
I had decided put a piece of the project here to all see the problem
When in the project please order by "nome sócio" and the tipe in the box "jo" and the project get the error we have speak here!
Thanks
Attached Files
Dec 7th, 2005, 09:36 AM
#18
Thread Starter
Frenzied Member
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Click Here to Expand Forum to Full Width