Thanks for the suggestions, but neither one seems to work. The record range does not seem to ever get updated when changing to a new data file unless a full merge completes using the new data, which does not help me.
So I have been working on a half binary search to find the correct data records. I found that if I try to set the record to use to a number higher than the new database has records I do get an error. So this is what I have come up with to try and get the record count:
set MyGuess to 20000
set StepBy to MyGuess
set TheDirection to "Up"
repeat until StepBy is 1
-- now we need to reset the direction and half the step
set TheDirection to "Up"
set StepBy to (round (StepBy / 2) rounding up)
tell application "Adobe InDesign CS5"
set myoriginal to document 1
tell data merge properties of myoriginal
tell data merge preferences
set record selection to one record
try
set record number to MyGuess
on error
set TheDirection to "Down"
end try
end tell
end tell
-- if the direction is still Up then we need to guess a higher number
-- if the direction has changed to down we need to guess a lower number
if TheDirection is "down" then
set MyGuess to (MyGuess - StepBy)
else
if StepBy is 1 then -- we have found our number
else -- set new step
set MyGuess to (MyGuess + StepBy)
end if
end if
-- if we ever go below 1 then there is no data in the indy file
if MyGuess is less than 1 then
set MyGuess to 0
end if
end tell
end repeat
return MyGuess
This is my first try at something like this, so I am sure that it made more simple. Also this works fine IF I have an even number for records. If my records are an odd number I am off by one. Not sure what I am doing wrong, or how to fix it, but I'm getting close.
If any one has any tips I would love to hear them.
Paul