微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

访问VBA-使用组合框时的类型不匹配多值字段

如何解决访问VBA-使用组合框时的类型不匹配多值字段

我有一个表单,一次显示一个记录,并允许通过在“文本框”和“组合框”中全部显示该记录来进行编辑。其中一些是基于查找字段的组合框,其中的值是从预设列表(多值字段)中提取的。

在那之后,我有一个类模块,为记录中的每个字段定义了一个属性一个FirstName属性一个LastName属性一个Address属性……您就知道了)。我有一个从类创建对象的函数,然后从表单中获取值并将它们分配给相应的属性。这对于大多数字段都适用,但是一旦到达第一个组合框(多项选择),它就会引发类型不匹配错误。我正在使用的代码是:

@(setlocal enableextensions enabledelayedexpansion
  echo off 
  set "DRNode=DRDB01"
)

CALL :Main

( ENDLOCAL
  CALL :End
  EXIT /B 0
)

:Main
  REM Loop Until the status of the cluster node indefinitly:

  CALL :Do_Until_Status "%DRNode%" "Joining"

  CALL :Restart_Cluster_Svc

  CALL :Do_Until_Status "%DRNode%" "Up"

  CALL :On_Status_Up

GOTO :EOF


:Do_Until_Status
    cluster.exe node %~1 /status
    cluster.exe node %~1 /status | FIND /I "%~1" | FIND /I "%~2" && ( GOTO :EOF)
GOTO :Do_Until_Status

:Restart_Cluster_Svc

  REM stop the cluster service and start it using force quorum
  net.exe stop clussvc  
  net.exe start clussvc /forcequorum  

GOTO :EOF

:On_Status_Up
  cluster.exe node DRDB01 /prop nodeweight=1 /prop:NodeWeight /status
  cluster.exe node PDCDB01 /prop nodeweight=0 /prop:NodeWeight /status
  cluster.exe node PDCDB02 /prop nodeweight=0 /prop:NodeWeight /status
GOTO :EOF
  

如果您想在ProfileObj对象的类模块中看到Property:

If Me.Issue <> vbNullString Then
ProfileObj.Issue = Me.Issue
End If
'Me.Issue is the comboBox on the form - this is in the forms module
'ProfileObj is the class instance

我也尝试使用Private ProfileIssue As String '... other variable declarations Property Get Issue() As String Issue = ProfileIssue End Property Property Let Issue(rData As String) ProfileIssue = rData End Property Me.Issue.ValueMe.Issue.Text来引用组合框,但是这些都不起作用。我什至尝试使用Me.Issue.Column(0),但无济于事。如何将组合框中显示的所有内容分配给String变量?

解决方法

我知道了...

我需要从每个组合框的.Text属性中读取文本。我已经在If语句中进行了尝试,但没有进行If语句建立的实际比较。该代码的工作版本现在显示为:

        Me.Issue.SetFocus 'You have to set focus in order to read the text,dont ask me why
        If Me.Issue.Text <> vbNullString Then 'This is where my code wasn't working
        .Issue = Me.Issue.Text 'I had tried it here before,but the code never got there since the line before failed
        End If

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。