English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Hi, i have a few problems with my code's. I am needed to create a database and link it with visual basic using data. I have done that. I also made a list box that gets populated with the 1 field from the db so u can select it easy. Now my code for delete button is this,

"rsmyrs.delete
lstrecords.removeitem lstrecords.listindex

call cmdclear_click"

When i run that (the code is out of a book) it get error at "cmdclear_click" however if i remove it, it works but after the records get deleted the information still stays in the box (until u select another box etc). Also how do i go about to promnt a box where it asks if i want to delete or not? The book in the code is this .. but it doesnt work.

Const strDelete As String = "Are you sure you want to delete this record?"

Dim resp As Integer

resp = MsgBox(strDelete, vbYesNo + vbQuestion + _
vbDefaultButton2, "Delete Record")

Call cmdClear_Click

End If
End Sub

2007-03-24 02:37:32 · 1 answers · asked by Anonymous in Computers & Internet Programming & Design

1 answers

1. The error that occurs on the "call cmdClear_Click" line is most likely due to there not actually being a cmdClear_Click procedure to call.

There should be the following procedure somewhere in the module:
Private Sub cmdClear_Click()
...
End Sub

If this subroutine is absent, then when it tries to call cmdClear_Click, the program is saying, "What? What am I supposed to call? There's nothing like that here."

2. The message box is not having an effect because you're not actually referencing the result anywhere. That is, when a person says "No," that response is stored in the "resp" variable... and then you don't do anything with it.

To fix this problem, fix the code to read the following (I'm going to skip copying most of the text here):

resp = MsgBox(strDelete, vbYesNo + vbQuestion + _
vbDefaultButton2, "Delete Record")

If resp = vbYes Then Call cmdClear_Click

2007-03-24 09:11:55 · answer #1 · answered by Katie M 2 · 0 0

fedest.com, questions and answers