我将数据从 frmSearchEmployeeWorksheets 发送到运行查询 (qryStatsCorr) 的 frmStatsCorr。在 frmStatsCorr 我正在检查以确保查询返回记录,否则我将向用户发送消息并返回到搜索表单。我的问题是我在“忽略”由我在 Stackoverflow 上学到的DoCmd.OpenForm ("frmStatsCorr")引起的 2501 时遇到问题...
我做错了什么导致我对 Access VBA 感到沮丧?
这是搜索表单 (frmSearchEmployeeWorksheets) 上的子项:
Private Sub btnSearch_Click()
' I only change focus to force the updated data to submit to query
Me.[txtEmployee].SetFocus
Me.txtShift.SetFocus
If txtUnit = "7" Then
'First close the form in order to update
DoCmd.Close acForm, "frmStatsCorr"
' Open Stats form
On Error GoTo myErr
**DoCmd.OpenForm ("frmStatsCorr") 'causes error**
End If
myExit:
Exit Sub
myErr:
Echo True
If Err.Number = 2501 Then GoTo myExit
MsgBox Err.Description
GoTo myExit
End Sub
在 frmStatsCorr 我只是检查以确保查询返回记录,如果不是我通知用户,关闭表单,然后返回到 frmSearchEmployeeWorksheets
Private Sub Form_Load()
If strFormStatus = "view" Then
If DCount("*", "qryStatsCorr") = 0 Then
MsgBox "Your search does not produce any results. Try a different search.", vbOKOnly
DoCmd.Close
DoCmd.OpenForm ("frmSearchEmployeeWorksheets")
Exit Sub
End If
txtDay = WeekdayName(Weekday(Me.WorkDate)) 'This line returns an error so I check for an empty query and return to the search form.
Me.[WorkDate].SetFocus
Me.txtUnit.Enabled = False...