Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Weird Problems when using delete button

Status
Not open for further replies.

Eric6

Programmer
Jun 11, 2002
54
CA
hi

i'm having some problems with my remove button
when clicked, it should delete the current record (displayed in the form)

i finally got the button to work properly
(i had to into the "form_Current" method to be able to change record after deletion but it works now)
my problem is,
Access now seems to randomly ask for confirmation...
most of the time, if its on the last record,
access will ask if you are sure you wish to remove the record (but not all the time!)
if the form is displaying anyother record,
most of the time, access wont even ask for confirmation,
it'll just delete it right away!
this is very bad and i need to figure out a way t fix this

i could make my own confirmation message but for that to work out, i would need to stop access from asking for confirmation 100% of the time

does anyone have any ideas as to what could be causing this?
please help

Eric
 
What code are you using to delete it, and where is it? What exactly did you put in the Form_Current event? If it's code for confirming and/or deleting, that's the problem. You shouldn't need to use the Form_Current when deleting a record. In the button's click event, you can use the following although there may be a better method:

Dim rst As Recordset
Set rst = Me.CurrentRecord
rst.Delete
Me.Requery

If Me.Requery doesn't work, try reopening the form.
DoCmd.OpenForm Me.Name
 
Software does not act randomly. For a given input, with no outside failures, it will perform the same every time. But I've sometimes gotten upset with myself for not being able to understand the issue or fix the problem.

Form_Open
DoCmd.DisplayAlerts = False ----------------------
Steve King
scking@arinc.com
Life is filled with lessons.
We are responsible for the
results of the quizzes.
-----------------------
 
here is the code for my remove button

If IsNull(Me.Function) Or IsNull(Me.Project) Then
MsgBox "You cannot remove an incomplete entry" &
vbCrLf & "Make sure Project and Function have values
Before trying to remove the entry.",
vbExclamation, "Complete Entry Before Removing"
Else
deleting = True
DoCmd.DoMenuItem A_FORMBAR, A_EDIT, A_SELECTRECORD
DoCmd.DoMenuItem A_FORMBAR, A_EDIT, A_DELETE
'here, it jumps to the form_current method
'because the delete action move records
End If

here is the code for my Form_current method
(this method is huge because it takes care of enabling and disabling the navigation buttons once i reach the BOF and EOF. I will not include it here for simplicity's sake)

If deleting Then
deleting = False
LastRec = LastRec - 1
If CurrentRecord <> 1 Then
DoCmd.GoToRecord , , acPrevious
Exit Sub
End If
End If

the reason i did it this way was that
the record that is being deleted contains required fields
the delete command worked fine but when i tried
change record (to go to the previous record) i would get an error.
it wouldn't let me change records because, after the record was deleted it would leave a blank form...
since the form was blank, access wouldn't let me change because the required fields were null

i hope i explained it properly
i'm pretty sure its my form_current method that's messing with the access confirmation messages
but i cant prove it, i haven't found the &quot;variable&quot; that causes the messages to display or not...
 
Yeah, the Current method is the problem. Everytime you go to a record, it is saying LastRec = LastRec - 1.
I tested the code on my system and found the following to work:

DoCmd.DoMenuItem A_FORMBAR, A_EDIT, A_SELECTRECORD
DoCmd.DoMenuItem A_FORMBAR, A_EDIT, A_DELETE
Me.Requery

This will delete the record, then refresh the form.
Just add Me.Requery after your menuitem commands, and you don't have to do anything else. Unless you use 'deleting' somewhere else, this would allow you to remove that as well as the procedure associated with it in Form_Current.
 
the thing is, it wont reach the lastrec - 1
unless the remove button has been pushed

and as soon as it enters the if, its set back to false

i dont see how that could stop access from warning the user
 
The Form_Current doesn't need any code to support a delete action.

DoCmd.SetWarnings = False
DoCmd.DoMenuItem A_FORMBAR, A_EDIT, A_SELECTRECORD
DoCmd.DoMenuItem A_FORMBAR, A_EDIT, A_DELETE
Me.Requery
DoCmd.SetWarning = True

----------------------
Steve King
scking@arinc.com
Life is filled with lessons.
We are responsible for the
results of the quizzes.
-----------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top