如何在 Access 2019 64 位中的组合框行源上使用多个联合

问题描述

我正在将 32 位 Access DB 前端转换为 64 位。我们有代码根据选中的复选框从链接视图动态构建 ID 和名称组合框的行源。这可能导致最多 6 个选择语句与 5 个“联合”语句组合。这适用于 32 位应用程序,但在 64 位应用程序中,如果行源 SQL 中存在多个联合,它会导致 Access 崩溃。作为测试,我尝试在合并的前两个选择周围放置括号,但没有奏效。

此代码旨在减少每次击键时下拉列表中的行数,因此每次击键时都会重建和重新查询行源。

例如,要查找名称 Jones,第一个构建 where 子句的名称将类似于 'J%',第二个构建将是 .... like 'Jo%' 等

windows 系统日志有这个崩溃信息:

    Faulting application name: MSACCESS.EXE,version: 16.0.10376.20033,time stamp: 0x60dff893
    Faulting module name: ACECORE.DLL,version: 0.0.0.0,time stamp: 0x608a909b
    Exception code: 0xc0000005
    Fault offset: 0x00000000000645bf
    Faulting process id: 0x198
    Faulting application start time: 0x01d78325d24d2c03
    Faulting application path: C:\Program Files\Microsoft Office\root\Office16\MSACCESS.EXE
    Faulting module path: C:\Program Files\Common Files\Microsoft Shared\Office16\ACECORE.DLL
    Report Id: 15ad9d88-d048-48ec-a0e9-1a8897aa7c8a
    Faulting package full name: 
    Faulting package-relative application ID: 

代码 Build_RowSrc:

  Const cstrProcNm As String = "Build_RowSrc"
  
  Const strStdSQL As String = "select lngPrsnId,strFullNm from vw_StdCrntMtrcCrtSpcl"
  Const strNDSpclStdSQL As String = "select lngPrsnId,strFullNm from vw_cboStdNDSpcl"
  Const strVisMedStdSQL As String = "select distinct lngPrsnId,strFullNm from vw_VisMedStdFullNm"
  Const strApptSQL As String = "select lngPrsnId,strFullNm from vw_cboPrsnAppts"
  Const strGradSQL As String = "select lngPrsnId,strFullNm from vw_cboJHUSOMGraduates"
  Const strCrtSpclSQL As String = "select lngPrsnId,strFullNm from vw_cboCrtSpclErnd"
  Const strUnion As String = " UNION "
  Dim strcboPrsnRowSrc As String
  
  strcboPrsnRowSrc = ""
  
  strWhere = " where strFullNm like '" & strLetterSelected & "%'"
  
  Select Case Me.cboRqstLtrTp
    Case cbyt_RqstLtrTp_Cert
      If Me.chkAppts = True Then
        strcboPrsnRowSrc = strApptSQL & strWhere
      End If
      
      If Me.chkGrad = True Then
        If Len(strcboPrsnRowSrc) > 0 Then
          strcboPrsnRowSrc = "(" & strcboPrsnRowSrc & strUnion & strGradSQL & strWhere & ")" & strUnion & strCrtSpclSQL & strWhere
        Else
          strcboPrsnRowSrc = strGradSQL & strWhere & strUnion & strCrtSpclSQL & strWhere
        End If
      End If
      
      If Me.chkStd = True Then
        If Len(strcboPrsnRowSrc) > 0 Then
          strcboPrsnRowSrc = strcboPrsnRowSrc & strUnion & strStdSQL & strWhere
        Else
          strcboPrsnRowSrc = strStdSQL & strWhere
        End If
      End If
      
      If Me.chkNDSpclStd = True Then
        If Len(strcboPrsnRowSrc) > 0 Then
          strcboPrsnRowSrc = strcboPrsnRowSrc & strUnion & strNDSpclStdSQL & strWhere
        Else
          strcboPrsnRowSrc = strNDSpclStdSQL & strWhere
        End If
      End If
      
      If Me.chkVisMedStd = True Then
        If Len(strcboPrsnRowSrc) > 0 Then
          strcboPrsnRowSrc = strcboPrsnRowSrc & strUnion & strVisMedStdSQL & strWhere
        Else
          strcboPrsnRowSrc = strVisMedStdSQL & strWhere
        End If
      End If
    Case cbyt_RqstLtrTp_JD,cbyt_RqstLtrTp_InsDscnt
      strcboPrsnRowSrc = "select lngPrsnId,strFullNm from vw_RqstLtrStd" & strWhere & _
        " UNION select lngPrsnId,strFullNm from vw_RqstLtrPDoc" & strWhere
    Case cbyt_RqstLtrTp_USMLE
      strcboPrsnRowSrc = "select distinct lngPrsnId,strFullNm from vw_RqstLtrUSMLE" & strWhere
    Case cbyt_RqstLtrTp_GJD,strFullNm from vw_RqstLtrPDoc" & strWhere
  
  End Select
  
  Build_RowSrc = strcboPrsnRowSrc & " order by strFullNm"

由 SetRecordSource 调用(当超过 1 个联合时,行源分配崩溃):

  Const cstrProcNm As String = "SetRecordSource"
  
  Dim strEntry As String
  Dim strLetterSelected As String
  
  strLetterSelected = Left$(Me.cboPrsn.Text,1)
  If (strLetterSelected <> mstrLastLetterSelected) Then
    
    If Len(Nz(Me.cboPrsn.Text,"")) > 0 Then
      With Me.cboPrsn
        .SetFocus
        
        .Text = ""
        .RowSource = Build_RowSrc(strLetterSelected)
        .Requery
        
        If .ListCount > 0 Then
          .ListIndex = 0
          .SelStart = 1
          .SelLength = Len(Nz(.Text,"")) 
          .Dropdown
        End If
        Debug.Print Time
      End With
    End If
    mstrLastLetterSelected = strLetterSelected
    
  End If  'Not strLetterSelected = Me.strLastLetterSelected

感谢任何指导。

挂钩

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...