previous record from new record

  • Thread starter Thread starter max
  • Start date Start date
M

max

Hi all,
I really do not have a clue why I get an error in the following situation.

I have this code associated to a cmd button on a form, to move to the
previous record:
------------------ start of code --------------------------
Private Sub cmdUndoNew_Click()
On Error GoTo Err_cmdUndoNew_Click

DoCmd.RunCommand acCmdRecordsGoToPrevious
medNum.SetFocus

Exit_cmdUndoNew_Click:
Exit Sub

Err_cmdUndoNew_Click:
MsgBox Err.Description
Resume Exit_cmdUndoNew_Click

End Sub
------------------ end of code -------------------------
this button appears when the recordset moves to a new record. Normally
pressing this button, provided that nothing has been written in the new
record (otherwise the button automatically disappear), the recordset moves
to the previuos record, the last of the recordset, canceling the new record
that was going to be filled in.
This button works perfectly using the form normally, while it gives the
error "the command or action CmdRecordsGoToPrevious isn't available now".
Does anybody have an idea why this is happening?

many thanks
Max
 
max said:
Hi all,
I really do not have a clue why I get an error in the following situation.

I have this code associated to a cmd button on a form, to move to the
previous record:
------------------ start of code --------------------------
Private Sub cmdUndoNew_Click()
On Error GoTo Err_cmdUndoNew_Click

DoCmd.RunCommand acCmdRecordsGoToPrevious
medNum.SetFocus

Exit_cmdUndoNew_Click:
Exit Sub

Err_cmdUndoNew_Click:
MsgBox Err.Description
Resume Exit_cmdUndoNew_Click

End Sub
------------------ end of code -------------------------
this button appears when the recordset moves to a new record. Normally
pressing this button, provided that nothing has been written in the new
record (otherwise the button automatically disappear), the recordset moves
to the previuos record, the last of the recordset, canceling the new record
that was going to be filled in.
This button works perfectly using the form normally, while it gives the
error "the command or action CmdRecordsGoToPrevious isn't available now".
Does anybody have an idea why this is happening?


The only thing that comes to mind is that there is no
previous record.
 
Hi Marsh
thanks for your reply
I'm sure there are records, 25, also because the forms normally works; what I've forgotten to specify is that the error occurs only when I run the application line by line with F8 placing a breakpoint at the beginning of the procedure
I really need to understand why this is happening, to prevent that the same error could happen when the application runs on another user's machine ..
Many thank

----- Marshall Barton wrote: ----

max wrote
Hi all
I really do not have a clue why I get an error in the following situation
previous record
------------------ start of code -------------------------
Private Sub cmdUndoNew_Click(
On Error GoTo Err_cmdUndoNew_Clic
MsgBox Err.Descriptio
Resume Exit_cmdUndoNew_Clic
------------------ end of code ------------------------
this button appears when the recordset moves to a new record. Normall
pressing this button, provided that nothing has been written in the ne
record (otherwise the button automatically disappear), the recordset move
to the previuos record, the last of the recordset, canceling the new recor
that was going to be filled in
This button works perfectly using the form normally, while it gives th
error "the command or action CmdRecordsGoToPrevious isn't available now"
Does anybody have an idea why this is happening


The only thing that comes to mind is that there is n
previous record
 
max said:
I'm sure there are records, 25, also because the forms normally works; what I've forgotten to specify is that the error occurs only when I run the application line by line with F8 placing a breakpoint at the beginning of the procedure.
I really need to understand why this is happening, to prevent that the same error could happen when the application runs on another user's machine ...


So the code has stopped executing and you are looking at the
code module, right?

If so, then you're original code is actually ok. I think
you've run into in the problem of DoCmd being a method of
the Application object, not the form object. You're trying
to tell the code module window to go to the previous record.

In general, I try to avoid DoCmd whenever there is any other
way to do the same job. In this case, here's another way:

With Me.RecordsetClone
.Bookmark = Me.Bookmark
If .AbsolutePosition > 0 Then
.MovePrevious
Me.Bookmark = .Bookmark
End If
End With
 
Hey Marsh,
I've just tried your code, and it works perfectly, both running the application, both debugging step by step.
Problem solved.
many thanks again for your help :)
Massimo


----- Marshall Barton wrote: -----
I'm sure there are records, 25, also because the forms normally works; what I've forgotten to specify is that the error occurs only when I run the application line by line with F8 placing a breakpoint at the beginning of the procedure.
I really need to understand why this is happening, to prevent that the same error could happen when the application runs on another user's machine ...


So the code has stopped executing and you are looking at the
code module, right?

If so, then you're original code is actually ok. I think
you've run into in the problem of DoCmd being a method of
the Application object, not the form object. You're trying
to tell the code module window to go to the previous record.

In general, I try to avoid DoCmd whenever there is any other
way to do the same job. In this case, here's another way:

With Me.RecordsetClone
.Bookmark = Me.Bookmark
If .AbsolutePosition > 0 Then
.MovePrevious
Me.Bookmark = .Bookmark
End If
End With
 
Back
Top