数据类型不匹配在SQL语句中。

huangapple go评论76阅读模式
英文:

Data Type Mismatch on SQL statement

问题

我试图从表格中提取列数据到VBA中的计时器。在我的表格中,IntervalSeconds是一个数字。我试图查询秒数以确定要设置计数器的持续时间。

Dim timeRemaining As Long (表单变量) - 用于多个函数中

Private Sub Form_Open(Cancel As Integer)
Dim strSQL As String
    
    Me.Visible = False
    
    strSQL = "SELECT AccessControl.IntervalSeconds FROM AccessControl WHERE AccessControl.DatabaseName = '" & CurrentDb.Name & "'"
    
    timeRemaining = CLng(strSQL)
    DoCmd.OpenForm ("frmForceLogout")

End Sub

每次运行表单时,当我执行timeRemaining = cLng(strSQL)这一行时,都会出现类型不匹配错误。我漏掉了什么吗?

英文:

I am trying to pull in column data from a table into a timer in VBA. In my table I have IntervalSeconds as a number. I'm trying to query the number of seconds to determine how long to set my counter for.

Dim timeRemaining As Long (Form Variable) - used in multiple functionss

Private Sub Form_Open(Cancel As Integer)
Dim strSQL As String
    
    Me.Visible = False
    
    strSQL = "SELECT AccessControl.IntervalSeconds FROM AccessControl WHERE AccessControl.DatabaseName = '" & CurrentDb.Name & "'"
    
    timeRemaining = CLng(strSQL)
    DoCmd.OpenForm ("frmForceLogout")

End Sub

Every time I run the form I get a Type Mismatch error when I hit the timeRemaining = cLng(strSQL) line. Am I missing something?

答案1

得分: 1

你可以使用 DLookup 来执行这样简单的任务:

Private Sub Form_Open(Cancel As Integer)

    Dim Criteria As String
    
    Me.Visible = False

    Criteria = "DatabaseName = '" & CurrentDb.Name & "'"
    timeRemaining = DLookup("IntervalSeconds", "AccessControl", Criteria)
    
    DoCmd.OpenForm ("frmForceLogout")

End Sub
英文:

You can use DLookup for such simple tasks:

Private Sub Form_Open(Cancel As Integer)

    Dim Criteria As String
    
    Me.Visible = False

    Criteria = "DatabaseName = '" & CurrentDb.Name & "'"
    timeRemaining = DLookup("IntervalSeconds", "AccessControl", Criteria)
    
    DoCmd.OpenForm ("frmForceLogout")

End Sub

</details>



huangapple
  • 本文由 发表于 2023年2月9日 01:59:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/75389919.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定