Jump 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.

Featured Replies

Afternoon Guys,

 

I could do with some help with following code:

 

Set objFM = WScript.CreateObject ('FMPRO.Application')¶

If objFM.ScriptStatus = 0 then¶

Set objFMfiles = objFM.Documents.Open(‘Database.fmp12','un','pw')¶

objFM.Visible = True¶

objFMfiles.DoFMScript ('OpenQuotationScript')¶

End If¶

 

This code basically opens a word doc after it has had it's bookmarks populated and closed.

 

The code works fine until a different user other than the one I used in the 'un' & 'pw' is logged in and then I get a WSH error.

 

So is there a way of using the Set objFMfiles = objFM.Documents.Open(‘Database.fmp12','un','pw') without needing to use a username & password or

somehow getting the Users username & password.

 

I have tried using GetObject instead of Open but with no success.

 

Any pointers would be most appreciated.

 

Kind regards,

Mark.

if FM is already running and the file open, then you don't need to issue the Open command, just loop through the FM documents collection until you have the right one targeted and then run the script

 

Set objFMfiles = objFM.Documents

 

is the collection (all open FM files)

  • Author

if FM is already running and the file open, then you don't need to issue the Open command, just loop through the FM documents collection until you have the right one targeted and then run the script

 

Set objFMfiles = objFM.Documents

 

is the collection (all open FM files)

Hi Wim,

 

Thanks for your response.

 

Not too sure what you mean by "just loop through the FM documents collection until you have the right one targeted and then run the script"

 

So is the code below what I should be looking at?.

 

Set objFM = WScript.CreateObject ('FMPRO.Application')¶

If objFM.ScriptStatus = 0 then¶

Set objFMfiles = objFM.Documents.DoFMScript ('OpenQuotationScript')

objFM.Visible = True¶

End If¶

No, something like this:

(I'm not on a Windows machine right so I can't check for syntax errors)

Set objFMfiles = objFM.Documents
for each objTargetFile in objFMfiles
  if objTargetFile.fullname = "Database" then
    objTargetFile.DoFMScript ('OpenQuotationScript')
  end if
next

Ideally you would shortcut the loop if you have found your target file obviously, no point in continuing the loop.

You also should clean up your objects and set them to nothing when you are done.

  • Author

No, something like this:

(I'm not on a Windows machine right so I can't check for syntax errors)

Set objFMfiles = objFM.Documents
for each objTargetFile in objFMfiles
  if objTargetFile.fullname = "Database" then
    objTargetFile.DoFMScript ('OpenQuotationScript')
  end if
next

Ideally you would shortcut the loop if you have found your target file obviously, no point in continuing the loop.

You also should clean up your objects and set them to nothing when you are done.

 Hi Wim,

 

Thanks for that.

 

I tried the following code:

 

Set objFMfiles = objFM.Documents¶
for each objTargetFile in objFMfiles¶
if objTargetFile.fullname = 'D&H Sales Database - Development.fmp12' then¶
objTargetFile.DoFMScript ('OpenAcknowledgementScript')¶
end if¶
next¶
Set objFMfiles = nothing¶
Set objFM = nothing¶
Set objTargetFile = nothing¶"
 
I got a WSH error - Object Required 'objFM'
 
Then I tried (with & without the .fmp12):
 
Set objFM = WScript.CreateObject ('FMPRO.Application')¶
Set objFMfiles = objFM.Documents¶
for each objTargetFile in objFMfiles¶
if objTargetFile.fullname = 'D&H Sales Database - Development.fmp12' then¶
objTargetFile.DoFMScript ('OpenAcknowledgementScript')¶
end if¶
next¶
Set objFMfiles = nothing¶
Set objFM = nothing¶
Set objTargetFile = nothing¶"
 
The error go but the objTargetFile.DoFMScript ('OpenAcknowledgementScript')¶ does not fire.
 
Kind regards, Mark.
  • Author

No, something like this:

(I'm not on a Windows machine right so I can't check for syntax errors)

Set objFMfiles = objFM.Documents
for each objTargetFile in objFMfiles
  if objTargetFile.fullname = "Database" then
    objTargetFile.DoFMScript ('OpenQuotationScript')
  end if
next

Ideally you would shortcut the loop if you have found your target file obviously, no point in continuing the loop.

You also should clean up your objects and set them to nothing when you are done.

Hi Wim,

 

I found some code on a google search that I had not spotted which works:

 

Set FMApp = CreateObject('FMPRO.Application')¶
Set FMDocs = FMApp.Documents¶
FMApp.Visible = True¶
Set FMActiveDoc = FMDocs.Active¶
FMActiveDoc.DoFMScript ('OpenAcknowledgementScript')¶
Set FMDocs = Nothing¶
Set FMActiveDoc = Nothing¶"
 
Many thanks for all you help.
 
Kind regards,

 

Set objFMfiles = objFM.Documents¶
for each objTargetFile in objFMfiles¶
if objTargetFile.fullname = 'D&H Sales Database - Development.fmp12' then¶
objTargetFile.DoFMScript ('OpenAcknowledgementScript')¶
end if¶
next¶
Set objFMfiles = nothing¶
Set objFM = nothing¶
Set objTargetFile = nothing¶"
 
I got a WSH error - Object Required 'objFM'
 

 

 

If this all the code you were using then you have not set or declared an "objFM" in your code, so you can't call it (1st line)

  • Author

If this all the code you were using then you have not set or declared an "objFM" in your code, so you can't call it (1st line)

Hi,

 

I did set/declare 'objFM':

 

Set objFM = WScript.CreateObject ('FMPRO.Application')¶
Set objFMfiles = objFM.Documents¶
for each objTargetFile in objFMfiles¶
if objTargetFile.fullname = 'D&H Sales Database - Development.fmp12' then¶
objTargetFile.DoFMScript ('OpenAcknowledgementScript')¶
end if¶
next¶
Set objFMfiles = nothing¶
Set objFM = nothing¶
Set objTargetFile = nothing¶"
 
But the script did not fire.
 
Regards, Mark.

Create an account or sign in to comment

Important Information

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

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.