Avatar billede dp2001 Juniormester
03. februar 2002 - 20:53 Der er 12 kommentarer og
1 løsning

Makro til søg og erstat

Jeg efterlyser en makro, der kan lave en søg og erstat. Jeg har haft kigget på "SøgEfterPost" - men denne giver ikke mulighed for erstat.

Hvad kan man lave, hvis det skal være en makro?

Den skal kunne erstatte feltværdier med data a la...

TEKST
-----
g}r    -> gær
}ble  -> æble

osv. og tilsvarende for en række andre specialtegn -> æ, ø, å, Æ, Ø og Å.

Nogle forslag?

Avatar billede terry Ekspert
03. februar 2002 - 21:22 #1
You call the function with

MyFld= fldUpdate("g}r")
   

'NOTE: To get the Ascii value of the character which is to be replaced.
'In the debug window (Ctrl+G) enter ?asc("}") and replace } with the character you want the value of.
'Then replace XXX in the Case in the code and remove comments :o)

Function fldUpdate(sIn As String) As String
Dim sWork As String
Dim i As Integer

    sWork = sIn
   
    For i = 1 To Len(sWork)
   
        Select Case Asc(Mid(sWork, i, 1))
       
            'Case XXX
            '    Mid(sWork, i, 1) = "å"
            'Case XXX
            '    Mid(sWork, i, 1) = "Å"
            Case 125
                Mid(sWork, i, 1) = "æ"
            'Case XXX
            '    Mid(sWork, i, 1) = "Æ"
            'Case XXX
            '    Mid(sWork, i, 1) = "ø"
            'Case XXX
            '    Mid(sWork, i, 1) = "Ø"
            Case Else
        End Select
       
    Next i
   
    fldUpdate = sWork

End Function
Avatar billede terry Ekspert
03. februar 2002 - 21:26 #2
In the example I have only converted } to æ, you have to find the ascii value of each character you want replacing and replace each XXX in the code.

You can also use this function form an update query by entering (for example)

fldUpdate([YourField])

in the Update to field. Where your replace YourField with the correct field name.
Avatar billede dp2001 Juniormester
03. februar 2002 - 22:04 #3
I don't really get it, since I'm not familiar with Visual Basic.

Do I have to make a module containing the above code and call this with a macro?

Need more help!
Avatar billede terry Ekspert
04. februar 2002 - 08:14 #4
Yes, place this in a new module.

What do you want to convert, data in a table? if so then make a new update query using the function as mentioned in my comment 21:26. You can then call the query either from a macro or youcan add a button to a form using the form wizard. You can get thew izard to run your query !
Avatar billede dp2001 Juniormester
04. februar 2002 - 11:38 #5
Getting closer....

I've made the module now and an update query.

However..when I run the update query I get the following error:

Der opstod en kompileringsfejl. (A compilation error was found).

Projektet eller bibliotektet kan ikke findes. (The project or library could not be found).
Avatar billede terry Ekspert
04. februar 2002 - 11:44 #6
! The code I sent MUST be in a module NOT in a form. When it is in a module all forms and queries have Access to it.
If you still getproblems then you can send it to dktebrsa@europe.lego.com and I will take a look!
Avatar billede dp2001 Juniormester
04. februar 2002 - 11:54 #7
OK. I've sent it to you now.
Avatar billede terry Ekspert
04. februar 2002 - 12:19 #8
I have received it and will get back as soon as possible :o)
Avatar billede terry Ekspert
04. februar 2002 - 12:48 #9
OK! Your problem is because you have a MISSING reference! In code view go to the Tools+References menu. You will see MISSING beside one of the references, remove the check in the check box. It shouls work now. But nothing is going to get converted! In the test data you sent there are NO characters which have to be converted.
Example:
} as in g}r whcih you wnat converting to æ

If you send me a list of the charcaters you want converting then I will correct the code. I need to know the characters to convert and to what they are to be converted to!
Avatar billede dp2001 Juniormester
04. februar 2002 - 13:07 #10
OK, I've removed the two checks in the check boxes.

What I want to convert is the following...

{ -> æ
| -> ø
} -> å
[ -> Æ
\ -> Ø
] -> Å
Avatar billede terry Ekspert
04. februar 2002 - 13:19 #11
Function fldUpdate(sIn As String) As String
Dim sWork As String
Dim i As Integer

    sWork = sIn
   
    For i = 1 To Len(sWork)
   
        Select Case Asc(Mid(sWork, i, 1))
       
            Case 125
                Mid(sWork, i, 1) = "å"
            Case 93
                Mid(sWork, i, 1) = "Å"
            Case 123
                Mid(sWork, i, 1) = "æ"
            Case 91
                Mid(sWork, i, 1) = "Æ"
            Case 124
                Mid(sWork, i, 1) = "ø"
            Case 92
                Mid(sWork, i, 1) = "Ø"
            Case Else
        End Select
       
    Next i
   
    fldUpdate = sWork

End Function
Avatar billede dp2001 Juniormester
04. februar 2002 - 14:32 #12
Bingo! It works!

Thank you very much for helping me here!
Avatar billede terry Ekspert
04. februar 2002 - 14:33 #13
no problem :o)
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