Skip to main content

Error Script

Hi,
I'm currently creating a script where by I am extracting some key statistics for individual locations for my company.  This information is then exported to an Excel Spreadsheet template populated with company norms (created by a separate macro) in order to provide a comparison. 
 
With some of the statistics, it is possible that some of them will not apply to all locations, and as such when I do a summarisation or direct extraction with the criteria defined, I end up with a blank database.  My issue is that as the statistics will apply to other locations and this is a generic one size fits all macro.  This blank database needs to be joined to another database containing other statistics so that all statistics are in one place.  When running the macro, it causes the file to be appended to, to lose all its data and also be blank.
 
Is there a way to write an error check to look at whether a database is blank and to include a "0" in the field instead of it being blank? 
 
 
SCRIPT:
"Set db = Client.OpenDatabase("COSUM - APDBK12MTHSTRAT1.IMD")
Set task = db.Extraction
task.IncludeAllFields
dbName = "PCSUM - " & CO & "-" & PCN & " APDBKSTRAT.IMD"
task.AddExtraction dbName, "", ExtEqn
task.CreateVirtualDatabase = False
task.PerformTask 1, db.Count
db.Close
Set task = Nothing
Set db = Nothing
Client.OpenDatabase (dbName)
 
Set db = Client.OpenDatabase("PCSUM - " & CO & "-" & PCN & " APDBKSTRAT.IMD")
Set task = db.Summarization
task.AddFieldToSummarize "CONO"
task.AddFieldToTotal "GOODSVAL"
task.Criteria = "BATCHTYPE =  ""OLD"" "
dbName = "PCSUM - " & CO & "-" & PCN & " OLDSUMM.IMD"
task.OutputDBName = dbName
task.CreatePercentField = FALSE
task.StatisticsToInclude = SM_SUM
task.PerformTask
Set task = Nothing
Set db = Nothing
Client.OpenDatabase (dbName)
 
Set db = Client.OpenDatabase("PCSUM - PCAVGS6.IMD")
Set task = db.JoinDatabase
task.FileToJoin "PCSUM - " & CO & "-" & PCN & " OLDSUMM.IMD"
task.IncludeAllPFields
task.AddSFieldToInc "GOODSVAL_SUM"
task.AddMatchKey "CONO", "CONO", "A"
task.CreateVirtualDatabase = True
dbName = "PCSUM - PCAVGS7.IMD"
task.PerformTask dbName, "", WI_JOIN_MATCH_ONLY
Set task = Nothing
Set db = Nothing
Client.OpenDatabase (dbName)"
 
 
INFO: "& CO &" and "& PCN &" are defined above with a text box. 
 
Many thanks,
Simon

Brian Element Mon, 05/20/2019 - 13:46

Before you do the join you can check if there are any items in the file such as:

Set db = Client.OpenDatabase("PCSUM - PCAVGS6.IMD")

if db.count = 0 then

      'Since you want items as a 0 maybe have a dummy file that you can join to that contains the information you want if the file is blank.

else

      'Perform Join

end if