Move to Previous Record

gmatriix

Registered User.
Local time
Today, 13:44
Joined
Mar 19, 2007
Messages
365
Hello All,

I have a code that adds a new record but it asks the user if they really want to do that. If they choose "no" I wanted it to go back to the previous record. This what I tried but it doesn't work.

Code:
Dim rs As Recordset

If Me.NewRecord Then
Me.productid.Visible = False
If MsgBox("Add a New Quote?", vbYesNo, "New Quote") = vbYes Then
Me.[Product ID] = Nz(DMax("[product ID]", "product"), 1000) + 1
Me.productid.Visible = True
Else
If vbNo Then
rs.MovePrevious
End If
End If
End If
End Sub

Any Ideas?
 
You could use;
Code:
If Me.NewRecord Then
     Me.productid.Visible = False
     If MsgBox("Add a New Quote?", vbYesNo, "New Quote") = vbYes Then
          Me.[Product ID] = Nz(DMax("[product ID]", "product"), 1000) + 1
          Me.productid.Visible = True
     Else
          DoCmd.GoToRecord acDataForm, "YourFormName", acPrevious

     End If
End If
End Sub
 
Thanks John,

But it doesn't move back...it seems like it should but it stays on the new record. Is it thinking that the new record is the previous record?

If I press new record, the nav buttons say "1 of 5265"....when I choose "no" on the msg box it should take me back to record I started on but it stays on "5265 of 5265"

Any Ideas?
 
I tested the code in the Form's On Current event and it works as expected. What event are you using?
 
On current like you...

It does work but it does not move back to the record I started on.

It does take me to the previous record....for example

  • I'm on the first record
  • I create a new record
  • Msgbox says" Do you want to do this?"
  • I say "no"
  • I'm wanting it to go back to the first record (or whatever record I was on)

Instead it goes to the last file as previous

Any way to do this?
 
If you want it to go back to the record you where on, then you are going to have to record the Record ID of the current record when the command to go to the New Record is issued, and then use the FindRecord method to find that record again.
 
If they choose "no" I wanted it to go back to the previous record.

If you know what is the current record, such as the current record in a Multiple Items form, then this will take you to the previous record if there is a different record above the current record:

Code:
  Dim daoRS As DAO.Recordset

  Set daoRS = Me.RecordsetClone
  With daoRS
    .FindFirst ("[aid] = " & lRecordID)
    If .NoMatch Then
      GoTo Exit_LocatePrevNextRecord
    End If

    'Now try moving to the previous record
    .MovePrevious

    'Check the operation return code
    If .BOF Or .EOF Then
      GoTo Exit_LocatePrevNextRecord
    End If
  End With

  'Clean up the connection to the database
  Set daoRS = Nothing
Where column [aid] has the AccessID of the record (an autonumber field) and lRecordID has the currently selected record's aid field value.
 
mdlueck,

getting compile error on
GoTo Exit_LocatePrevNextRecord

John,

I did this
Code:
Dim sProduct As Long

Me.[Product ID] = sProduct
If Me.NewRecord Then
     Me.productid.Visible = False
     If MsgBox("Add a New Quote?", vbYesNo, "New Quote") = vbYes Then
          Me.[Product ID] = Nz(DMax("[product ID]", "product"), 1000) + 1
          Me.productid.Visible = True
     Else
         'DoCmd.FindRecord "sProduct", , True, , True

     End If
End If
End Sub

Sorry Im still learning....it just spun and did not find anything
 
getting compile error on
GoTo Exit_LocatePrevNextRecord

That was not all of the function, rather air code. I was expecting you to insert the code into a template function shell, and update the naming based on the function name you are placing it into.

Example of my function/subroutine/property shell, for a function which happens to be named Update():

Code:
Public Function Update() As Boolean
On Error GoTo Err_Update

  'Good return code
  Update = True

Exit_Update:
  Exit Function

Err_Update:
  Call errorhandler_MsgBox("Class: clsObjUIValidationAOETbl, Function: Update()")
  Update = False
  Resume Exit_Update

End Function
 

Users who are viewing this thread

Back
Top Bottom