This example shows you how to record a script to find X and replace with Y across all records. We will use a Do... Loop, and use "If X do this, else do that", If-Then-Else statements. The example we will use is changing IC Creditor codes.
(Alt+F1) to start recording.(F11).(F9).F8 to select the next record.(Alt+F1) to turn off the script recorder.Dim frmICProd1 as Object
frmICProd1 = CreateObject("Accredo.ICProductForm")
frmICProd1.Edit
frmICProd1.CreditorCode = "FORD"
frmICProd1.Save
frmICProd1.Next
Dim frmICProd1 as Object
frmICProd1 = CreateObject("Accredo.ICProductForm")
Do until frmICProd1.EOF
frmICProd1.Edit
frmICProd1.CreditorCode = "FORD"
frmICProd1.Save
frmICProd1.Next
Loop
If you leave out the frmICProd1.Next you will end up with an infinite loop which never reaches the EOF. To break out of this, press ESC or Alt+F1.
Result: This script will change every creditor code to FORD regardless of what the original code is.
Dim frmICProd1 as Object
frmICProd1 = CreateObject("Accredo.ICProductForm")
Do Until frmICProd1.EOF
If frmICProd1.CreditorCode = "CONWAY" then
frmICProd1.Edit
frmICProd1.CreditorCode = "FORD"
frmICProd1.Save
End If
frmICProd1.Next
Loop
FromValue = InputCode("APCRED", "From Creditor Code", "From Code")
If IsNull(FromValue) Then Abort("Cancelled by user")
ToValue = InputCode("APCRED", "To Creditor Code", "To Code")
If IsNull(ToValue) Then Abort("Cancelled by user")
Dim frmICProd1 as Object
frmICProd1 = CreateObject("Accredo.ICProductForm")
Do Until frmICProd1.EOF
If frmICProd1.CreditorCode = FromValue then
frmICProd1.Edit
frmICProd1.CreditorCode = ToValue
frmICProd1.Save
End If
frmICProd1.Next
Loop
frmICProd1.Close
FromValue = InputCode("APCRED", "From Creditor Code", "From Code")
If IsNull(FromValue) then Abort("Cancelled by user")
ToValue = InputCode("APCRED", "To Creditor Code", "To Code")
If IsNull(ToValue) then Abort("Cancelled by user")
Count = 0
Dim frmICProd1 as Object
frmICProd1 = CreateObject("Accredo.ICProductForm")
Do Until frmICProd1.EOF
If frmICProd1.CreditorCode = FromValue then
frmICProd1.Edit
frmICProd1.CreditorCode = ToValue
frmICProd1.Save
Count = Count+1
End If
frmICProd1.Next
Loop
frmICProd1.Close
Print Count & " instances of Creditor Code " & FromValue & " found"
Print "and replaced by Creditor Code " & ToValue & "."