Skip to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

exit script if error

Featured Replies

Hi, I have a script that exports records to a csv file. after it has exported it displays an OK dialog.

The problem is that sometimes the previously exported file might be open already, thus resulting in the "file could not be created on this disk". It then proceeds to the OK dialog.

How can I exit the script once this error comes up, instead of it coming up with the OK dialog? or make it display a "process failed, please rerun" dialog?

thanks

This is default Windows Reaction to when you try to overwrite a currently open file -- nothing to do with FM. You might script the death of that file before exporting using VBScript. Try the following... put this in a field:

Dim wsh, appRunning

Set wsh = CreateObject("Wscript.Shell")

appRunning = True

Do While appRunning = True

appRunning = wsh.AppActivate("[color:red]My CSV file.csv")

If appRunning Then

Wscript.Sleep 200 'give time for focus shift

wsh.SendKeys "%{F4}"

End If

WScript.Sleep 500

Loop

This code will kill any open application with that red part in the title.

So export the field contents where you store the above code to a .vbs file, and run after export -- this effectively closes the open csv document before you run your export script -- hence preventing any errors.

Other than that... your stuck with it.

Check out the Set Error Capture script statement.

This allows you to trap for errors that would ordinarily display as the dialog box you describe - but you must take control in your script.

I'm not a hundred % sure error capture will work there but... maybe ive been playing with vb too much. :P

  • Author

thanks for the reply, i can't fit the vb script in a field though, i have tried to create a calculation field that brings in two fields that make up the two halfs of the script. But i can't get that to work. How do i go about fitting it in?

many thanks, apologies if its a blatantly obvious answer but my knoweldge is still quite sketchy in the basic aspects of FM.

I am so confused... what do you mean you can't fit it? Just copy the code, and paste it into a field (it doesn't matter if it doesnt "visually fit").

Then export that field to a file with a .vbs extension and turn on execute after export or whatever

  • Author

oh yeah, i was thinking of the default calculated field value. thanks a lot it works!

is there any way to kill the "do you want to save changes" dialog when it tries to close the file?

cheers

The File?

or do you mean the Edit Boxes? Why would you want to kill them, they are trying to save you from yourself?

Lee

No no, they mean the .csv file that gets opened post export.

Create an account or sign in to comment

Important Information

By using this site, you agree to our Terms of Use.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.