Desktop User Guides > Professional > Troubleshooting > Data Management troubleshooting > Event section problems
 
Event section problems
When I use the For Each...Next syntax with the Questions collection, I get an execute error: “Method call failed: Does not support a collection”. Why is this and what is the solution?
You will get this error when the script encounters a complex question like a loop or a block, which is represented by DMOM as a nested Questions collection. mrScriptBasic attempts to expand the default and fails. Therefore you should always test for the question type on the first line of the For Each...Next loop. For example:
Dim objQuestion, NestedQuestion
For Each objQuestion in dmgrQuestions
  If objQuestion.QuestionType <> QuestionTypes.qtSimple Then
    For Each NestedQuestion in objQuestion
    .
    .
    Next
  End If
Next
For a cleaning example that illustrates this, see Example 6: Advanced cleaning example.
My cleaning script fails with an “Undefined variable” error that then names a variable that is definitely in the data being transferred. Why is this?
Check that you included the variable in the SelectQuery statement in the InputDataSource section (see InputDataSource section). Only variables that are explicitly named in the SelectQuery statement are available as Question objects to mrScriptBasic in the OnJobStart, OnNextCase, and OnJobEnd Event sections. Remember that if you are creating new variables in the Metadata section, you need to include them in the SelectQuery statement too.
However, if your InputDataSource section does not contain a SelectQuery statement or uses a "SELECT * FROM vdata" query, all of the variables in the InputDataSource and Metadata section are automatically included.
How can I access the name or full name of a variable in my cleaning script? For example, if I want to write the name or full name to a report file?
You can access the variable's name and full name using the QuestionName and QuestionFullName properties of the Question object.
Is there any way of getting the category name that corresponds to the response(s) stored in the case data in a categorical variable?
You can get the category name for a response to a categorical question from the Category.Name property. You can get the Category object from the Question.Categories collection. If the question response contains a single value, you can use it as the index into the collection. For an example, see the MSExcelDataViewer.dms sample. See Sample DMS files that integrate with Microsoft Office for more information.
If the question response contains more than one value, you can use each value as an index into the collection. For an example of iterating through the values in a multiple response variable, see the CreateDRS.dms sample. See Sample DMS files for more information.
I am trying to use the question response value as an index into the Question.Categories collection, but I get an “Object required when accessing <Property Name>” error. What could be causing this?
One common reason for this is that there is a NULL value in the case data. Try using “Is Not Null” to filter out the NULL values. For an example of doing this, see the MSExcelDataViewer.dms sample. See Sample DMS files that integrate with Microsoft Office for more information.
Another reason for this error is that the response in the case data does not correspond to a category in the metadata. Typically this happens when the category has been deleted in the current version of the metadata and the case data was collected using an earlier version in which the category was present. You can avoid this problem by selecting all versions of the metadata in the InputDataSource section. For an example of doing this, see the CreateDRS.dms sample. See Sample DMS files for more information.
How can I script my DMS file to stop? For example, when I encounter an error that makes me want to stop the run altogether.
You can stop the job by raising an error and not trapping it. For example:
On Error Goto 0
Err.Raise(1, , "Job stopped")
Some of the samples use “Is Not NULL”, rather than “<> NULL” to test for a Null value. Why is this?
You are likely to get incorrect results when you use “<> NULL” to test for a NULL value in mrScriptBasic. This is because the comparison operations treat NULL values as empty or zero values, depending on the data type. This does not happen when you use “Is Not NULL”. For more information, see Null values.
When I use the DefinedCategories function with a DMOM Question object in the OnNextCase Event section, the DMS file fails with “An error occurred calling the function 'DefinedCategories': No variable ID given”. Why is this?
Unfortunately there is a problem (mrBug00012862), which means that you cannot use the DefinedCategories function with the DMOM Question object in UNICOM Intelligence Professional 2.1. However, you can get a list of a Question object's categories using the Question.Categories property.
I am having problems getting my DMS file to run. It is using the Metadata Model to Quantum object and is failing on the line highlighted below. What is going wrong?
Event(OnBeforeJobStart, Set up the card, column, and punch definitions)
 Dim M2Q, MDM, HasPunchDSC, i                                ' 1
 Set MDM = CreateObject("MDM.Document")                      ' 2
 MDM.Open("C:\MDD files\test.mdd")                           ' 3
 ' Check whether a Quantum DSC DataSource object already
   exists                                                    ' 5
 HasPunchDSC = False                                         ' 6
 If MDM.DataSources.Count > 0 Then                           ' 7
   For i = 0 To MDM.DataSources.Count - 1                    ' 8
     If MDM.DataSources.Item[i].CDSCName = "mrPunchDsc" Then ' 9
       Set MDM.DataSources.Current = MDM.DataSources.Item[i] ' 10
       HasPunchDSC = True
       Exit For
     Else
       HasPunchDSC = False
     End If
   Next
  End If
 If HasPunchDSC = False Then
   Set MDM.DataSources.Current =
        MDM.DataSources.AddNew("mrPunchDsc", "mrPunchDsc",
        "C:\DAT    files\test.dat")
End If
...
This is probably an issue with case-sensitivity. The comparison on line 9 is case-sensitive, which means that if there is a DataSource object named “mrPunchDSC”, the comparison will fail. To solve this problem, change line 9 to the following (the changes are highlighted):
If LCase(MDM.DataSources.Item[i].CDSCName) = "mrpunchdsc" Then
For more on mrScriptBasic troubleshooting, see mrScriptBasic FAQs and troubleshooting.
See also
Data Management troubleshooting