English 中文(简体)
从母体表中获取记录的中度错误 2105
原标题:Run-time error 2105 when accessing records from parent form button

I have a parent form with a data sheet subform containing records. The parent form has a button that modifies the selected subform record by calling a procedure on the subform. The current record number is stored in a variable, the procedure requeries the subform which removes the record, and then uses the variable to go to that record number (which in theory will go to the previous record available assuming it s not the first or last record). There can be 100 s of entries so it s important for the users that after the requery they aren t returned to the first record.

同一程序可以通过双重点击该次表上的任何领域。

相关守则:

Public Sub AddRemoveFromReport()
On Error GoTo ErrCheck
    dblLineNo = Nz(Me.CurrentRecord, 1)
    If Me.OnReport = True Then
        Me.OnReport = False
    Else
        Me.OnReport = True
    End If
    Me.Requery
    Me.Parent.frmPRJTrackerReportDetailTempOnReport.Form.Requery
    Me.Parent.frmPRJTrackerReportDetailTempAvailable.Form.Requery
    Application.Echo False
    Me.Requery
    DoCmd.GoToRecord acActiveDataObject, , acLast
    DoCmd.GoToRecord acActiveDataObject, , acGoTo, dblLineNo
    Application.Echo True
    Exit Sub
ErrCheck:
    Select Case Err.Number
        Case 2427
            MsgBox "Please select an item from the list before continuing.", vbOKOnly + vbInformation
        Case 2105
             // Last record selected, Go to the previous record instead
            DoCmd.GoToRecord acActiveDataObject, , acGoTo, dblLineNo - 1
            Application.Echo True
            Resume Next
        Case Else
            MsgBox Err.Description
    End Select
    Application.Echo True
End Sub

When double clicking any fields on the record the code executes fine, but when executing the same code from the parent form the run time error occurs regardless of position within the recordset. The dblLineNo has the correct record number, it just seems to fail when attempting acGoTo.

I ve searched everywhere for an answer to this but haven t been able to find a solution. Any help would be greatly appreciated.

问题回答

你似乎只是更新了目前记录的一个单一领域,因此尝试了这种做法,而这种做法不需要重新排序:

Public Sub AddRemoveFromReport()

    Dim Records As DAO.Recordset

    Set Records = Me.RecordsetClone

    If Records.RecordCount > 0 Then
        Records.Bookmark = Me.Bookmark
        Records.Edit
            Records!OnReport.Value = Not Records!OnReport.Value
        Records.Update
    End If
    Records.Close

End Sub

经过更多的测试,我发现出现错误的原因。

由于荷兰语在母体上被点击,似乎不承认在孩子上课时具有积极性。

The solution was to add me.Childform.SetFocus to the button routine prior to running the code. I also removed acActiveDataObject from the GoToRecord command. Just removing acActiveDataObject didn t resolve the issue and neither did just using SetFocus. I also removed the MoveLast line as it wasn t required.

更新(简明扼要) 法典:

Public Sub AddRemoveFromReport()
On Error GoTo ErrCheck

    dblLineNo = Nz(Me.CurrentRecord, 1)
    If Me.OnReport = True Then
        Me.OnReport = False
    Else
        Me.OnReport = True
    End If
    Me.Requery
    Me.Parent.frmPRJTrackerReportDetailTempOnReport.Form.Requery
    Me.Parent.frmPRJTrackerReportDetailTempAvailable.Form.Requery
    Me.Requery
    DoCmd.GoToRecord , , acGoTo, dblLineNo
    Exit Sub
ErrCheck:
    Select Case Err.Number
        Case 2427
            MsgBox "Please select an item from the list before continuing.", vbOKOnly + vbInformation, "JobMan"
        Case 2105
             // First or Last record selected, Go to the previous record instead
            If dblLineNo = 1 Then
                DoCmd.GoToRecord acActiveDataObject, , acGoTo, acFirst
            Else
                DoCmd.GoToRecord acActiveDataObject, , acGoTo, dblLineNo - 1
            End If
            Application.Echo True
            Resume Next
        Case Else
            MsgBox Err.Description
    End Select
    Application.Echo True
End Sub

我希望这能帮助任何可能出现这一问题的人。





相关问题
Handling no results for docmd.applyfilter

I have an Access app where I use search functionality. I have a TextBox and a Search Button on the form, and it does a wildcard search of whatever the user enters in the TextBox, and displays the ...

Outlook 2007 CommandBarControl.Execute won t work

I recently switched to Outlook 2007 and noticed that my VBA-macros won t work. I use the following code to open a new appointment-item (and fill it automatically). It worked perfect in Outlook 2003, ...

Connecting to Oracle 10g with ODBC from Excel VBA

The following code works. the connection opens fine but recordset.recordCount always returns -1 when there is data in the table. ANd If I try to call any methods/properties on recordset it crashes ...

MS Access: list macro from VBA

I have to deal with a few macros (not VBA) in an inherited Access application. In order to document them, I would like to print or list the actions in those macros, but I am very dissatisfied by ...

热门标签