【问题标题】:Could you explain why is in attach code below the syntax error?你能解释一下为什么在语法错误下面的附加代码中吗?
【发布时间】:2021-12-18 16:27:13
【问题描述】:

你能解释一下为什么在attach code下面有语法错误吗?

If Me.DateBeign <> "" And Me.DateEnd <> "" Then 
q = "SELECT * FROM Controls WHERE [Begin dates of control] = # " & Me.DateBegin & " # AND [End dates of controls ] = # " & Me.DateEnd & " # "
    Me.RecordSource = q
End If

【问题讨论】:

  • 你为什么让我们猜测错误是什么?
  • 包含错误信息!
  • 首先是运行时错误:3075 connect with date format,是 2465,它说它找不到某个字段,这个查询不关心

标签: sql forms if-statement ms-access syntax-error


【解决方案1】:

除了可能拼错的控件名称之外,请尝试以下完整语法:

If Not IsNull(Me!DateBegin.Value + Me!DateEnd.Value) Then 
    q = "SELECT * FROM Controls WHERE [Begin dates of control] = #" & Format(Me!DateBegin.Value, "yyyy\/mm\/dd") & "# AND [End dates of control] = #" & Format(Me!DateEnd.Value, "yyyy\/mm\/dd") & "#"
    Me.RecordSource = q
End If

另外,让你的两个文本框的Format属性都被分配了一个Date格式。

【讨论】:

  • 我不同意这个解决方案。在这个论坛上看到同样的问题,我认为问题是连接所有“sings with ' 另一方面:如何为访问 VBA 中的文本框分配日期格式(我需要放置此代码)跨度>
  • 如果您的日期字段的数据类型为 DateTime,它将起作用。如果不是(文本),请修改它,因为日期永远不应该存储为文本。
  • 所以我把 DateValue(Me.Text28) 放在这里。但现在我正在测试来自不同论坛的版本
  • 充其量,它不会添加任何东西;在最坏的情况下,麻烦。 Me.Text28 是什么?但是,如果[Begin dates of control]Text,则要么修改它以保存DateTime,要么(暂时)转换为日期:DateValue([Begin dates of control])
  • textx28 是 TextBox 的名称,我在其中放置了开始日期,我将其转换为日期类型。从另一个论坛我发现问题出现在最后一个“#”中。运行时错误号 3075 是在找不到这个带有双引号的符号的情况下出现的。
猜你喜欢
  • 2021-08-14
  • 2021-10-27
  • 2011-04-20
  • 2016-07-25
  • 2018-04-14
  • 1970-01-01
  • 1970-01-01
  • 2023-03-26
相关资源
最近更新 更多