Avatar billede moeslund Nybegynder
31. januar 2002 - 12:49 Der er 8 kommentarer og
1 løsning

Ændring af format i Access 2000

Jeg har en masse adresseregistreringer der er konverteret fra et andet databasesystem til Access. Posten "navn" står nu i access som eks.

JENSEN/KARL
HANSEN/ALICE

Hvordan får jeg byttet om på for- og efternavn og erstattet / med et mellemrum eks.

KARL JENSEN
ALICE HANSEN

Evt. skrive en kode i format feltet ?


Avatar billede terry Ekspert
31. januar 2002 - 13:00 #1
make a module and place the folloowing code in it.
Function cNavn(sin As String) As String
Dim sWork As String
Dim i As Integer

    sWork = sin
   
    i = InStr(1, sin, "/")
       
    sWork = Mid(sin, i + 1, Len(sin) - i) & " "
    sWork = sWork & Left(sin, i - 1)

    Debug.Print sWork
   
    cNavn = sWork

End Function

Then you make an update query setting the update To field to

CNavn([navn])
Avatar billede terry Ekspert
31. januar 2002 - 21:24 #2
Hows it going?

you can delete the line
Debug.print sWork
Avatar billede moeslund Nybegynder
01. februar 2002 - 11:43 #3
Hi Terry,

Thank you for your help ! :-) - it works !

But there is an error runtime error '5' - when I debug this statement is outlined:
sWork = sWork & Left(sin, i - 1)

I have about 14.000 names but only the first 1.400 names are changed. - I have tried to deled name 1.401 an activate the query again with no change.

Hope this makes sense
Avatar billede terry Ekspert
01. februar 2002 - 12:24 #4
add this to the start of the function after the
Dim i As Integer line

If isNull(sin) then exit function

and see if that helps
Avatar billede moeslund Nybegynder
01. februar 2002 - 13:52 #5
It?s the  same ? is it possible to skip the names that causes the error ?
Avatar billede terry Ekspert
01. februar 2002 - 14:22 #6
I am trying to skip those which cause the error, but it isnt always easy to know what the field contains. Try this:

Function cNavn(sin As String) As String
Dim sWork As String
Dim i As Integer

    sWork = sin
   
    i = InStr(1, sin, "/")

    if i = = Then
      Cnavn = ""
      Exit Function
    end if

    sWork = Mid(sin, i + 1, Len(sin) - i) & " "
    sWork = sWork & Left(sin, i - 1)
   
    cNavn = sWork

End Function
Avatar billede moeslund Nybegynder
01. februar 2002 - 15:12 #7
It cant compile this statement: if i = = Then

Again thank you for your effort ! :-)
Avatar billede terry Ekspert
01. februar 2002 - 21:37 #8
if I = 0 Then
Avatar billede moeslund Nybegynder
02. februar 2002 - 13:32 #9
Yes ! This time it went through all the names – there were 255 names with wrong format -  these were skipped.

Thanks again :-)
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Dyk ned i databasernes verden på et af vores praksisnære Access-kurser

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester