无聊的背景,我正在尝试如何使用 Access 正确实现 VBA - 另一方面 - 希望在我的工作地点改进一个非常原始的 Access“应用程序”。管理是心态,如果“它”有效(无论多么糟糕),为什么要尝试改进“它”?
话虽如此,一个表单被用来显示要打开以进行编辑的表格列表。主窗体包含选择下拉框和最初链接到表格的子窗体。我正在尝试在子表单中打开选定的表,以便用户删除不需要处理的记录(这正在工作,这要归功于 stackoverflow.com)。
无论如何,用户选择表,然后创建 sql 语句。
选择 [PLS_Elkins_072513].[结构编号], [PLS_Elkins_072513].[结构注释], [PLS_Elkins_072513].[结构注释 2], [PLS_Elkins_072513].[结构注释 3], [PLS_Elkins_072513].[结构注释 4], [ PLS_Elkins_072513].[结构注释 5], [PLS_Elkins_072513].[结构注释 6], [PLS_Elkins_072513].[结构注释 7], [PLS_Elkins_072513].[结构注释 8], [PLS_Elkins_072513].[结构注释 9], [ PLS_Elkins_072513].[结构注释 10], [PLS_Elkins_072513].[结构注释 11], [PLS_Elkins_072513].[结构注释 12], [PLS_Elkins_072513].[结构注释 13], [PLS_Elkins_072513], [结构注释 1] PLS_Elkins_072513].[结构注释 15], [PLS_Elkins_072513].[结构注释 16], [PLS_Elkins_072513].[结构注释 17], [PLS_Elkins_072513].[结构注释 18], [PLS_Elkins_072513]。[结构注释 19], [PLS_Elkins_072513].[结构注释 20], [PLS_Elkins_072513].[结构注释 21], [PLS_Elkins_072513].[结构注释 22], [PLS_Elkins_072513].[结构注释 23], [PLS_Elkins_07251] [结构注释 24], [PLS_Elkins_072513].[结构注释 25], [PLS_Elkins_072513].[结构注释 26], [PLS_Elkins_072513].[结构注释 27], [PLS_Elkins_072513].[结构注释 28], [PLS_Elkins_07251] [结构注释 29], [PLS_Elkins_072513].[结构注释 30], [PLS_Elkins_072513].[结构注释 31], [PLS_Elkins_072513].[结构注释 32], [PLS_Elkins_072513].[结构注释 33], [PLS_Elkins_07251] [结构注释 34],[PLS_Elkins_072513]。[结构注释 35],[PLS_Elkins_072513]。[结构注释 36],[PLS_Elkins_072513]。[结构注释 37],[PLS_Elkins_072513]。[结构注释 38],[PLS_Elkins_072513].[结构注释 39], [PLS_Elkins_072513].[结构注释 40], [PLS_Elkins_072513].[结构注释 41], [PLS_Elkins_072513].[结构注释 42], [PLS_Elkins_072513], 注释 4 [PLS_Elkins_072513].[结构注释 44], [PLS_Elkins_072513].[结构注释 45], [PLS_Elkins_072513].[结构注释 46], [PLS_Elkins_072513].[结构注释 47], [PLS_Elkins_072513], 注释 4 [PLS_Elkins_072513].[结构注释 49],[PLS_Elkins_072513].[结构注释 50] 来自 PLS_Elkins_072513;[PLS_Elkins_072513].[结构注释 46], [PLS_Elkins_072513].[结构注释 47], [PLS_Elkins_072513].[结构注释 48], [PLS_Elkins_072513].[结构注释 49], [PLS_Elkins_072513]. [结构注释 5] PLS_Elkins_072513;[PLS_Elkins_072513].[结构注释 46], [PLS_Elkins_072513].[结构注释 47], [PLS_Elkins_072513].[结构注释 48], [PLS_Elkins_072513].[结构注释 49], [PLS_Elkins_072513]. [结构注释 5] PLS_Elkins_072513;
以下代码用于设置记录集
Me.sfrmTempTable.Form.RecordSource = strSQL
接下来我得到一个对话框,要求我输入 51 个字段的参数值……我按了“输入”51 次……
VBA代码...
Private Sub EditStakingTable_Click()
Dim strSQL As String
Dim SelectTable As String
On Error GoTo Err_Handler
SelectTable = Me.InputTable.Value
' Check for a blank table name
If SelectTable = "" Then
MsgBox "No Table Selected!!!", vbInformation, "Please select a table for editing."
Exit Sub
End If
' Process - 6/13/13
' DoCmd.SetWarnings False ' Turn off warnings
strSQL = "SELECT [" & SelectTable & "].[Structure Number], [" & SelectTable & "]. [Structure Comment 1], [" & SelectTable & "].[Structure Comment 2], [" & SelectTable & "]. [Structure Comment 3], ["
strSQL = strSQL & SelectTable & "].[Structure Comment 4], [" & SelectTable & "]. [Structure Comment 5], [" & SelectTable & "].[Structure Comment 6], [" & SelectTable & "]. [Structure Comment 7], ["
strSQL = strSQL & SelectTable & "].[Structure Comment 8], [" & SelectTable & "]. [Structure Comment 9], [" & SelectTable & "].[Structure Comment 10], [" & SelectTable & "]. [Structure Comment 11], ["
strSQL = strSQL & SelectTable & "].[Structure Comment 12], [" & SelectTable & "]. [Structure Comment 13], [" & SelectTable & "].[Structure Comment 14], [" & SelectTable & "].[Structure Comment 15], ["
strSQL = strSQL & SelectTable & "].[Structure Comment 16], [" & SelectTable & "].[Structure Comment 17], [" & SelectTable & "].[Structure Comment 18], [" & SelectTable & "].[Structure Comment 19], ["
strSQL = strSQL & SelectTable & "].[Structure Comment 20], [" & SelectTable & "].[Structure Comment 21], [" & SelectTable & "].[Structure Comment 22], [" & SelectTable & "].[Structure Comment 23], ["
strSQL = strSQL & SelectTable & "].[Structure Comment 24], [" & SelectTable & "].[Structure Comment 25], [" & SelectTable & "].[Structure Comment 26], [" & SelectTable & "].[Structure Comment 27], ["
strSQL = strSQL & SelectTable & "].[Structure Comment 28], [" & SelectTable & "].[Structure Comment 29], [" & SelectTable & "].[Structure Comment 30], [" & SelectTable & "].[Structure Comment 31], ["
strSQL = strSQL & SelectTable & "].[Structure Comment 32], [" & SelectTable & "].[Structure Comment 33], [" & SelectTable & "].[Structure Comment 34], [" & SelectTable & "].[Structure Comment 35], ["
strSQL = strSQL & SelectTable & "].[Structure Comment 36], [" & SelectTable & "].[Structure Comment 37], [" & SelectTable & "].[Structure Comment 38], [" & SelectTable & "].[Structure Comment 39], ["
strSQL = strSQL & SelectTable & "].[Structure Comment 40], [" & SelectTable & "].[Structure Comment 41], [" & SelectTable & "].[Structure Comment 42], [" & SelectTable & "].[Structure Comment 43], ["
strSQL = strSQL & SelectTable & "].[Structure Comment 44], [" & SelectTable & "].[Structure Comment 45], [" & SelectTable & "].[Structure Comment 46], [" & SelectTable & "].[Structure Comment 47], ["
strSQL = strSQL & SelectTable & "].[Structure Comment 48], [" & SelectTable & "].[Structure Comment 49], [" & SelectTable & "].[Structure Comment 50] FROM " & SelectTable & ";"
Debug.Print strSQL
Stop
' 8 / 09 / 13
Me.sfrmTempTable.Form.RecordSource = strSQL
' After tblStakingEdit has been opened, edited and closed
' copy (or rename) the tblStakingEdit table back to
' the originally named table
'DoCmd.SetWarnings True ' All done, turn on warnings back on.
Exit_Here:
Exit Sub
Err_Handler:
If Err.Number = 2101 Then
'Me.frmtesting.Visible = True
'ignore or message
Else
MsgBox Err.Description
End If
Resume Exit_Here
End Sub
代码运行后,我回到了原始屏幕,但子表单中的所有字段都显示“#Name?”。
最终产品的屏幕截图网址“ http://i138.photobucket.com/albums/q245/yosso22/Work%20Pictures/accessvba/final_screenshot_error_zpsa8ecb3a8.png ”
必须有一些我忽略的东西,因为我可以说是在“飞行”中学习。我确实购买了一本 MVP 书籍“访问解决方案”,其中有很多很好的例子,但现在我不知所措,正在向 stackoverflow.com 集体寻求帮助。:-)