simple record navigation problem

viperstingray

Registered User.
Local time
Today, 06:58
Joined
May 31, 2005
Messages
87
Hello,

I have a little problem and do require help in fixing it. I am only 3% away from finishing the database (due today) but have a little bit of a problem on my hands. here it is:

I have a counter on my form that tracks which record is currently being viewed. the code for the counter is:

------counter code---------
'Provide a record counter for using with
' custom navigation buttons (when not using
' Access built in navigation)

Dim rst1 As DAO.Recordset
Dim lngCount As Long

Set rst1 = Me.RecordsetClone

With rst1
.MoveFirst
.MoveLast
lngCount = .RecordCount

End With

'Show the result of the record count in the text box (txtRecordNo)
If Me.CurrentRecord = lngCount Then
Command126.Enabled = False
Command129.Enabled = False
Else
Command126.Enabled = True
Command129.Enabled = True
End If
Me.txtRecordNo = "Record " & Me.CurrentRecord & " of " & lngCount & " record(s) for " & [CLIENT PREFIX]
Me.Text292 = "Record " & Me.CurrentRecord & " of " & lngCount & " records"
----------counter code---------

On the same form, I have a delete button. The button deletes the current record that is being viewed (user prompted before it is deleted). The code for that button is as follows:
----delete code-----
Private Sub command271_Click()
On Error GoTo Err_cmdDelete_Click

DoCmd.SetWarnings False
If MsgBox("Are you sure you want to delete this Audit and its associated measures?", vbQuestion + vbYesNo + vbDefaultButton2, "Delete?") = vbYes Then
DoCmd.RunCommand acCmdSelectRecord
DoCmd.RunCommand acCmdDeleteRecord

CLIENT_NAME.SetFocus
End If
Exit_command271_Click:
DoCmd.SetWarnings True
Exit Sub
Err_cmdDelete_Click:
MsgBox Err.Description
Resume Exit_command271_Click
End Sub
-------delete code--------

This button also works fine with the exception of the following.
THE MAIN PROBLEM: example
I have a client that has 5 different entries in my database (5 diff. facilities) and I want to delete one of their facilities. I would simply use my 'search' form and then navigate to the facility that I would want to delete. If that facility is facility 1, 2, 3, or 4 then I have no problems. The system deletes the selected record and then simply displays the one after. The PROBLEM is when you are trying to delete the 5th record. When the fifth (in this example, it could be the 9th record for any other client, as long as it is the last one) is the one to be deleted, an error occurs. When you hit the debug button the following line from the counter is highlighted: .MoveLast

I have solved this problem and I no longer get an error message BUT when the last record is deleted, the database simply loads a new and empty form that will accept data. I DO NOT WANT THIS TO HAPPEN. I want it to be set up as follows:
If the last record (not the ONLY record, but the last record on file) is the one that is to be deleted THEN delete that record and load the one prior
If there is ONLY ONE record, then delete it and load the main form.

CAN ANYONE HELP.
 
Why reinvent the wheel? Record X of Y

You could test if the current record is new then move to the first or last record if you do not want the current record to be a new [blank] record after your custom delete command button is clicked.
 
i have already read the Record x of y post and could not implement it into my database, i'm kind of new at this. Do you see any way that I may program my delete button to recognize that it is deleting the last record for a client and when that record is deleted, then load the one previous?
 

Users who are viewing this thread

Back
Top Bottom