Setting Filemaker field value to variable

I can’t find the solution to this anywhere, hopefully you can help.
I’m writing an applescript that controls BBEdit’s wonderful find and replace function to modify a link in a web page. The value it modifies is based on a LastName field in a Filemaker database.
Here is the problem:
When I set the variable LastName in Filemaker, BBEdit errors during the replace step. But when I set the variable directly all works fine.

Here is how I set the variable in Filemaker:

tell application "FileMaker Developer" tell current record of layout "data_entry_T" --script doesn't work if setting LastName using Filemaker set LastName to cell "Last Name" as string end tell end tell
When I set the variable LastName directly the script works.

set LastName to "Thiessen"

This is the first time I’ve pulled data from Filemaker using applescript, could it be a text encoding problem?
I’ve analyzed the Script Editor Event log and everything appears OK.
Here is the step BBEdit errors on:

replace LastName using "test" searching in linklist saving yes options s_option

The error from BBedit is:
“BBEdit got an error /Users/mthiesse/desktop/BALOG-BBVWRG-0012379.htm” doesn’t understand replace message."
Here is the entire code:

tell application "FileMaker Developer" tell current record of layout "data_entry_T" set LastName to cell "Last Name up" as string end tell end tell tell application "BBEdit" --script works when I set LastName using line below --set LastName to "Balog" set linklist to "/Users/mthiesse/desktop/" & LastName & "-" & "BBVWRG" & ".htm" set s_option to {search mode:literal, starting at top:true, case sensitive:false, match words:true, extend selection:false, showing results:false} replace LastName using "test" searching in linklist saving yes options s_option end tell

Try this. It may or may not work but I believe I had a similar problem with Filemaker 4

after this code

tell application “FileMaker Developer”
tell current record of layout “data_entry_T”
–script doesn’t work if setting LastName using Filemaker
set LastName to cell “Last Name” as string
end tell
end tell

–do this

set LastName to LastName as text
set LastName to result