www.Inmagic.com    Inmagic Forums    Inmagic Forums  Hop To Forum Categories  Scripting    An auto update
Go
New
Find
Notify
Tools
Reply
  
-star Rating Rate It!  Login/Join 
AT
Posted
Hi there,

I wrote this script for my individual records, which worked perfectly Smile:

On RecordSave ()
{
var srcBox = Form.boxes("Consign");
if (srcBox)
{
var srcText = srcBox.content;
if (srcText != "")
{
var tgtBox = Form.boxes("NewCC");
if (tgtBox && tgtBox.content == "")
{
var allWords = srcText.split("/");
tgtBox.content = allWords[0];
}
}
}
}

Problem was we have 58,000 records in the database and I didn't want to have to go into each individual record to update the cost code so I had a go at this (by putting a button on my query screen):

function update_onClick()
{
var crs = Application.activeTextbase.currentRecordset;
if ((crs != null) && (crs.RecordCount > 0))
{
crs.MoveFirst();
while (crs.EOF == false)
{

var srcBox = Form.boxes("Consign");
if (srcBox) // be sure there is a box with the given name
{
var srcText = srcBox.content;
if (srcText != "") // proceed only if the first box is nonempty
{
var tgtBox = Form.boxes("NewCC");
if (tgtBox && tgtBox.content == "") // second box must exist and be empty
{
var allWords = srcText.split("/"); // allWords is an array of words
tgtBox.content = allWords[0];
}
}
}
}
{
crs.Update();
crs.MoveNext();
}
}
}

Which doesn't work Frown Now I think somewhere in my meddling I've got very confused - probably between var's and crs's. Anybody have a better, cleaner, way of doing this? Or can they point out what a wally I am by higlighting all my errors?
Ax
 
Posts: 65 | Location: Essex | Registered: Fri April 29 2005Reply With QuoteEdit or Delete MessageReport This Post
Posted Hide Post
You can't use Form.boxes("boxname").content in a recordset script. You have to change the actual field contents (using crs.Fields("boxname").Value), not the box contents. There is no box in a recordset script.

There is an example in the DB/TextWorks help at the bottom of the "Recordset Object" topic.
 
Posts: 217 | Registered: Wed June 29 2005Reply With QuoteEdit or Delete MessageReport This Post
AT
Posted Hide Post
That would explain a lot! Roll Eyes

I've looked at the example but it seems very complicated and I'm having problems working out what parts I need.

All i need the button to do (when pressed) is open all the records then save them. The form script I have should do the rest.

I'm starting to think batch modify may be easier than a script.
 
Posts: 65 | Location: Essex | Registered: Fri April 29 2005Reply With QuoteEdit or Delete MessageReport This Post
AT
Posted Hide Post
Well I'm still trying to work this one out - I hate being beaten!

Still not working and I'm trying a different variation. I just want the records in a database to open and save and then close when you click the button
Any ideas anyone? Smile

function Update_onClick()
{
Application.message("Starting batch modify.");
var crs = Application.activeTextbase.currentRecordset;
var validCt = 0;
if ((crs != null) && (crs.RecordCount > 0))
{
crs.MoveFirst();
while (crs.EOF == false)
{
Command.editRecord(); Command.saveRecord(); Command.closeWindow();
crs.Update();
validCt = validCt + 1;
crs.MoveNext();
}
}
Application.message(validCt+" records modified.");
}

Although it seems to work my other scripts don't i.e. I have an script to auto fill a field when the record has saved but when i run the update (which has Command.save Record) the field isn't automatically filled

This message has been edited. Last edited by: AT,
 
Posts: 65 | Location: Essex | Registered: Fri April 29 2005Reply With QuoteEdit or Delete MessageReport This Post
Posted Hide Post
As far as I know, one cannnot combine recordSet scripts and normal scripts (the Command.editRecord stuff) as you're trying to do. If you want to modify field contents using a recordset script, you must do so by modifying the crs.Fields("fieldname").Value.
 
Posts: 217 | Registered: Wed June 29 2005Reply With QuoteEdit or Delete MessageReport This Post
 Previous Topic | Next Topic powered by eve community  
 

www.Inmagic.com    Inmagic Forums    Inmagic Forums  Hop To Forum Categories  Scripting    An auto update