Next Record advancement main/sub form

Nyanko

Registered User.
Local time
Today, 08:56
Joined
Apr 21, 2005
Messages
57
Hi,

I have a an invoicing database that has a main/sub form setup. Each subform row has a unique RowID and an InvoiceID - the InvoiceID is the field that connects the sub to the main.

I want to add a "Next" button that advances the main form InvoiceID without going through all the rows in the subform that are attached to it.

eg.

InvoiceID 10010 has 3 RowIDs
InvoiceID 10011 has 2 RowIDs
InvoiceID 10012 has 5 RowIDs

The next button should take one press to advance between the InvoiceIDs.

This works perfectly when using the default record selectors at the bottom of the main form, but when I try to add a VBA button it takes 3 presses to get through InvoiceID 10010, 2 presses for InvoiceID 10011 etc....

I've also tried to incorporate a check to ensure that no new records are created :

Code:
Private Sub btn_NextButton_Click()
'------------------------------------------------------------
' CONTROL FOR NEXT BUTTON
'------------------------------------------------------------
On Error GoTo btn_NextButton_Click_Err
Dim test As Long
    On Error Resume Next
    'Don't go beyond the maximum records
     If Me.CurrentRecord < Me.Recordset.RecordCount Then
        DoCmd.GoToRecord acDataForm, "frm_MainInput", acNext
    Else
        Beep
        MsgBox "Last Record Displayed", vbOKOnly, ""
    End If
    
    If (MacroError <> 0) Then
        Beep
        MsgBox MacroError.Description, vbOKOnly, ""
    End If

btn_NextButton_Click_Exit:
    Exit Sub

btn_NextButton_Click_Err:
    MsgBox Error$
    Resume btn_NextButton_Click_Exit

Why isn't this working as I would like ?
Apologies in advance for any n00bness on my part
 
put the button on the main form:

Code:
Private Sub btn_NextButton_Click()
'------------------------------------------------------------
' CONTROL FOR NEXT BUTTON
'------------------------------------------------------------
Dim lngInvoice As Long
Dim rs As DAO.Recordset
lngInvoice = Nz(Me.InvoiceID, 0)
On Error GoTo btn_NextButton_Click_Err
Set rs = Me.RecordsetClone
With rs
    .FindFirst "[InvoiceID] = " & lngInvoice
    If Not .NoMatch Then
        .MoveNext
        If Not .EOF Then
            Me.Bookmark = .Bookmark
        Else
            Beep
            MsgBox "Last Record Displayed", vbOKOnly, ""
        End If
    End If
End If
btn_NextButton_Click_Exit:
    Set rs = Nothing
    Exit Sub

btn_NextButton_Click_Err:
    MsgBox Error$
    Resume btn_NextButton_Click_Exit
End Sub
 

Users who are viewing this thread

Back
Top Bottom