PDA

Click to See Complete Forum and Search --> : Error! Please Help


GRAHAM
May 16th, 2000, 05:02 AM
This is my first shot at a db application, and I have not been given any tuition on error handling at Uni. My app. works i.e I can add, search for records, but the delete function cases a problem. When I close the app. and open the db again, the record has been deleted, so the code is working in some fashion.

The problem happens when I select Yes in the MsgBox... I have to select Yes twice before the Msgbox closes, then all other functions cease to work.

Could someone point out the problem in the code, and show me where to insert some error handling. The code I am using is as follows

Private Sub cmdDelete_Click()

Set rs = db.OpenRecordset("SELECT wagedetails.name, wagedetails.grade, wagedetails.department, wagedetails.taxallowance From wagedetails WHERE wagedetails.name = " + Chr$(34) + txtName.Text + Chr$(34) + ";")

MsgBox "This action will permanently delete the record. Do you wish to continue?", vbYesNo, "Delete Record"
If MsgBox("This action will permanently delete the record. Do you wish to continue?", vbYesNo, "Delete Record") = vbYes Then
With rs
.Delete
.MovePrevious
.Close
End With
Else
rs.MovePrevious
End If

End Sub

Any help would be very much appreciated
GRAHAM :)

[Edited by GRAHAM on 05-16-2000 at 07:59 PM]

May 16th, 2000, 07:25 AM
graham,

you first call the MsgBox-Procedure and then the MsgBox-Function again. Do:

-----------------------------------------------------------

Private Sub cmdDelete_Click()

Dim strQuest As String, strSql As String

strSql = "Select wagedetails.name, wagedetails.grade, wagedetails.department, wagedetails.taxallowance From wagedetails Where wagedetails.name = '" & txtName.Text & "'"

strQuest = "This action will permanently delete " & _
"the record. Do you wish to continue?"

Set rs = db.OpenRecordset(strSql)
With rs
If MsgBox(strQuest, vbYesNo, "Delete Record") = vbYes Then
.Delete
.MovePrevious
.Close
Else
.MovePrevious
End If
End With

End Sub

-----------------------------------------------------------

maybe it would be better to use an action-query, like:

-----------------------------------------------------------

Private Sub cmdDelete_Click()

Dim strSql As String, strQuest As String

strSql = "Delete From wagedetails Where wagedetails.name='" & txtName.Text & "'"

strQuest = "This action will permanently delete " & _
"the record. Do you wish to continue?"

If MsgBox(strQuest, vbYesNo, "Delete Record") = vbYes Then
db.execute strSql
End If

End Sub

-----------------------------------------------------------

best regards

Clunietp
May 16th, 2000, 01:32 PM
be careful with this statement:

strSql = "Delete From wagedetails Where wagedetails.name='" & txtName.Text & "'"

make sure you ALWAYS delete by the primary key field (or other unique field) so you don't nuke more records than you planned on....

GRAHAM
May 17th, 2000, 04:14 AM
Thanks for responding, Sascha and Clunietp, I can utilise some of the code. I do have a unique ID number for each employee, and I will reference that instead.

I still need to provide some error handling....can you give me some ideas please.

Regards
GRAHAM :)