我的表单由表单标题,详细信息部分和表单页脚(设计模式)分隔。所有表格字段都列在详细信息部分。
我必须让它以这种方式工作 - 当我点击人的名字(显示为超链接)时,详细信息部分必须显示表中的记录,其中name字段值等于我单击的值。显示的字段数应保持不变。
我在VB上写了一个程序:
Private Sub GE_PERSON_Click()
Dim strSQL As String
strSQL = "SELECT GENERIC.GE_ID, GENERIC.GE_OPEN AS [OPEN], Workforce.WF_NAME AS PERSON, [GENERIC].[GE_DATEIN] AS RECEIVED, GENERIC.GE_DATEREQUESTED AS [STARTING DATE], GENERIC.GE_CONSECUTIVE AS CONSECUTIVE, GENERIC.GE_AMOUNT AS [DAYS TAKEN], ABSENCE.AB_TYPE AS [ABSENCE TYPE], [GENERIC].[GE_STATUS] AS STATUS"
strSQL = strSQL + "FROM (GENERIC INNER JOIN Workforce ON GENERIC.[GE_PERSON] = Workforce.[WF_ID]) INNER JOIN ABSENCE ON GENERIC.[GE_TYPE] = ABSENCE.[AB_ID]"
strSQL = strSQL + "WHERE WORKFORCE.[WF_NAME] = " + Form_GENERIC.GE_PERSON
strSQL = strSQL + "ORDER BY GENERIC.GE_DATEREQUESTED;"
Form_GENERIC.RecordSource = strSQL
End Sub
当我将strSQL
分配给Form_GENERIC.RecordSource
时,我收到错误消息。我无法将形成的字符串中的数据发送到主窗体GENERIC Record Source - 它会导致错误
运行时错误3141:SELECT语句包括拼写错误或缺失的保留字或参数名称,或者标点符号不正确
绝对需要你的帮助!
答案 0 :(得分:1)
连接字符串时,请确保在每行的开头或结尾包含空格。否则,字符串会被推到一起,导致您看到的错误。
E.g。如果你这样做
strSQL = "SELECT field1, field2"
strSQL = strSQL + "FROM table"
你最终得到了这个
"SELECT field1, field2FROM table"
添加空格以防止错误
strSQL = "SELECT field1, field2"
strSQL = strSQL + " FROM table"
^
put a space at the start of each concatenated line