Custom Nav Buttons

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am using the code below on a form but for some reason when the previous or
First button is clicked while within a new record, it won't respond. ie. no
error, no movement. The form itself is set at open to disallow
edits/additions/deletions until an appropriate button has been selected
(edit/delete etc) at which time the property for the relevant action is
changed. I've tried gotorecord / runcommand variations and Last/Previous with
no luck. Am I just being thick and missing something obvious? Any help is
muchly appreciated.

Private Sub cmdprevious_Click()
On Error GoTo Err_cmdprevious_Click
Dim response As String

If Me.NewRecord Then
response = MsgBox("This record is not complete and will be lost if you
continue. Continue?", vbYesNo)
Select Case response
Case 7 'vbNo
Exit Sub
Case 6 'vbyes
Me.AllowDeletions = True
DoCmd.RunCommand acCmdDeleteRecord
Me.AllowDeletions = False
DoCmd.GoToRecord , , acPrevious
End Select
Else
DoCmd.GoToRecord , , acPrevious

End If

Exit_cmdprevious_Click:
Exit Sub

Err_cmdprevious_Click:
MsgBox Err.Description
Resume Exit_cmdprevious_Click

End Sub
 
Let me see if I can get you a little farther along. To start, it is
particularly tough to *keep* access from saving edited records, new or
otherwise. I'm certain Access will save a new record if you changed something
and then move to any other record. Keeping Access from doing that requires
code.

Your particular problem is caused by the fact that 'response' will *never* match
any of your Case statements since you are comparing a number to a string. A
MsgBox() returns an Integer and not a String, but you Dimed it as a String.

You will probably run into problems since you can not delete a record that has
not been saved yet. Me.NewRecord AND Me.Dirty indicates you are on a New record
that has some changes and has not been saved yet. In this case a Me.Undo will
clear the Dirty and allow you to change records without saving anything.

I am using the code below on a form but for some reason when the previous or
First button is clicked while within a new record, it won't respond. ie. no
error, no movement. The form itself is set at open to disallow
edits/additions/deletions until an appropriate button has been selected
(edit/delete etc) at which time the property for the relevant action is
changed. I've tried gotorecord / runcommand variations and Last/Previous with
no luck. Am I just being thick and missing something obvious? Any help is
muchly appreciated.

Private Sub cmdprevious_Click()
On Error GoTo Err_cmdprevious_Click
Dim response As String

If Me.NewRecord Then
response = MsgBox("This record is not complete and will be lost if you
continue. Continue?", vbYesNo)
Select Case response
Case 7 'vbNo
Exit Sub
Case 6 'vbyes
Me.AllowDeletions = True
DoCmd.RunCommand acCmdDeleteRecord
Me.AllowDeletions = False
DoCmd.GoToRecord , , acPrevious
End Select
Else
DoCmd.GoToRecord , , acPrevious

End If

Exit_cmdprevious_Click:
Exit Sub

Err_cmdprevious_Click:
MsgBox Err.Description
Resume Exit_cmdprevious_Click

End Sub

_______________________________________________
hth - RuralGuy (RG for short)
Please post to the NewsGroup so all may benefit.
 
Oops. I forgot to change that back (the DIM). It was originally set as
Integer but I tried string as well since other posts indicated that worked as
well. Not so in this case, apparently.

If the issue is the saving of the record then would it be safe to say that
forcing a save then executing the delete should do the trick?
 
Once you have saved then I'm pretty sure Me.NewRecord goes false. Therefore
with your existing code if Me.Dirty is True, a Me.Undo will be all that is
required, no delete is necessary or possible.

Oops. I forgot to change that back (the DIM). It was originally set as
Integer but I tried string as well since other posts indicated that worked as
well. Not so in this case, apparently.

If the issue is the saving of the record then would it be safe to say that
forcing a save then executing the delete should do the trick?

_______________________________________________
hth - RuralGuy (RG for short)
Please post to the NewsGroup so all may benefit.
 
Back
Top