2

有一个非常奇怪的问题。我有一个在表单字段获得焦点时调用的函数。该函数传递四个参数,其中三个是来自表单字段的值,第四个是在表单加载时设置的全局变量。该函数使用这些变量来计算调用该函数的字段的值。这个函数在两个不同的地方被调用。一切工作正常,现在突然从一个地方调用该函数而从另一个地方调用时该函数工作,产生 2467 运行时错误,“您输入的表达式指的是一个关闭或不存在的对象'。我检查了传递的参数值是否正确,函数存在正常,所以不明白为什么会出现这个错误。有人有什么想法吗?

Private Sub cboFinalStage_GotFocus()
  'lookup stage based on TNM values
  cboFinalStage = FindStage(cboFinalStageT, cboFinalStageN, cboFinalStageM, gblCancer)
End Sub


Public Function FindStage(cboT As ComboBox, cboN As ComboBox, cboM As ComboBox,  
  strCancer As String) As String
  'use the TNM values entered to find the correct stage for the site and return it
  'error handling
  If gcfHandleErrors Then On Error GoTo PROC_ERR

  'declare variables
  Dim strTemp As String
  Dim strTable As String
  Dim db As DAO.Database
  Dim rs As DAO.Recordset
  Dim strQuery As String
  Dim strSite As String
  Dim strSiteFull As String
  Dim strT As String
  Dim strN As String
  Dim strM As String

  'initialise variables - if there are no values entered in the 3 comboboxes, exit 
  'load tumour first in case it isn't already loaded
  Forms!frmContainer.subTumour.SourceObject = "fsubTumour"
  If Not IsNull(Forms!frmContainer.subTumour.Form!txtICD10) Then
    strSite = Left(Forms!frmContainer.subTumour.Form!txtICD10, 3)
    strSiteFull = Forms!frmContainer.subTumour.Form!txtICD10
  End If
  If Not IsNull(cboT.Value) Then
    strT = cboT.Value
    Debug.Print "T is " & strT
  End If
  If Not IsNull(cboN.Value) Then
    strN = cboN.Value
    Debug.Print "N is " & strN
  End If
  If Not IsNull(cboM.Value) Then
    strM = cboM.Value
    Debug.Print "M is " & strM
  End If
  If (IsNull(strT) Or IsNull(strN) Or IsNull(strM)) Then
    Debug.Print "null so exiting"
    Exit Function
  End If

  'identify the correct AJCC lookup table by cancer site
  Select Case [strCancer]
    Case "bla"
        strTable = "lkp_AJCC_bladder"
    Case "bre"
        strTable = "lkp_AJCC_breast"
    ...
  End Select
  Debug.Print "AJCC table is " & strTable

  'query the AJCC lookup table for the stage
  strQuery = "SELECT c_stage FROM " & strTable & " WHERE (((t_value)='" & strT & "')
   AND ((n_value)='" & strN & "') AND ((m_value)='" & strM & "'))"
  Debug.Print "query is " & strQuery
  Set db = CurrentDb
  Set rs = db.OpenRecordset(strQuery)
  If Not rs.EOF Then
    strTemp = rs.Fields(0).Value
    Debug.Print "result is " & strTemp
  End If
  rs.Close
  db.Close

  'return stage
  FindStage = strTemp

'error handling
PROC_EXIT:
  Exit Function
PROC_ERR:
  If (Err.Number = 2467) Then
    MsgBox "Unable to evaluate the stage", vbOKOnly, "Processing error"
    Resume PROC_EXIT
  Else
    MsgBox "Error: (" & Err.Number & ") " & Err.Description, vbCritical
    Resume PROC_EXIT
  End If
End Function
4

0 回答 0