Delete record

  • Thread starter jervin via AccessMonster.com
  • Start date
J

jervin via AccessMonster.com

Hi,
Whats wrong with my second Code? does not delete the record....
pls help...thanks

Code No 1 (this one is working)
************************
Private Sub Ctl_delete_Click()
On Error GoTo a
If MsgBox("Do you want to DELETE this req ?", vbQuestion + vbYesNo, "Delete
Req?") = vbYes Then
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
End If
a:
End Sub
***********************
Code No 2 (this is not working)
******************
Private Sub checkpaassword_Click()
If IsNull(Forms!frmpassIss!Text0.Value) Then
MsgBox "It is not a blank Password...Try again."
Me!Text0.SetFocus

End If
If (Forms!frmpassIss!Text0 <> "vincent") Then
MsgBox "Wrong Password...Try again."
Me!Text0.SetFocus
End If
If (Forms!frmpassIss!Text0 = "vincent") Then
On Error GoTo a
If MsgBox("Do you want to DELETE this req ?", vbQuestion + vbYesNo,
"Delete Req?") = vbYes Then
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
DoCmd.Close acForm, "frmpassIss"
End If

a:
End If

End Sub
**********************
 
D

Douglas J. Steele

So what does happen? Do you get an error message? If so, what is it? Do you
get any of the message boxes appearing? If so, which one(s)?

The End If definitely should not be after line a.

Putting error trapping into your routine would probably be a good idea to
help debug problems. As well, your code could be better written as:

Private Sub checkpaassword_Click()

On Error GoTo Err_checkpaassword_Click

If IsNull(Forms!frmpassIss!Text0.Value) Then
MsgBox "It is not a blank Password...Try again."
Me!Text0.SetFocus
ElseIf (Forms!frmpassIss!Text0 <> "vincent") Then
MsgBox "Wrong Password...Try again."
Me!Text0.SetFocus
Else
If MsgBox("Do you want to DELETE this req ?", vbQuestion + vbYesNo,
"Delete Req?") = vbYes Then
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
DoCmd.Close acForm, "frmpassIss"
End If
End If

End_checkpaassword_Click:
Exit Sub

Err_checkpaassword_Click:
MsgBox Err.Number & ": " & Err.Description
Resume End_checkpaassword_Click

End Sub
 
J

jervin via AccessMonster.com

There is no error appear, It will just prompt me " Do you want to delete this
req?" yes and no option, But when i click yes my record is still there it
wont delete...thanks for quick reply

So what does happen? Do you get an error message? If so, what is it? Do you
get any of the message boxes appearing? If so, which one(s)?

The End If definitely should not be after line a.

Putting error trapping into your routine would probably be a good idea to
help debug problems. As well, your code could be better written as:

Private Sub checkpaassword_Click()

On Error GoTo Err_checkpaassword_Click

If IsNull(Forms!frmpassIss!Text0.Value) Then
MsgBox "It is not a blank Password...Try again."
Me!Text0.SetFocus
ElseIf (Forms!frmpassIss!Text0 <> "vincent") Then
MsgBox "Wrong Password...Try again."
Me!Text0.SetFocus
Else
If MsgBox("Do you want to DELETE this req ?", vbQuestion + vbYesNo,
"Delete Req?") = vbYes Then
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
DoCmd.Close acForm, "frmpassIss"
End If
End If

End_checkpaassword_Click:
Exit Sub

Err_checkpaassword_Click:
MsgBox Err.Number & ": " & Err.Description
Resume End_checkpaassword_Click

End Sub
Hi,
Whats wrong with my second Code? does not delete the record....
[quoted text clipped - 39 lines]
End Sub
**********************
 
D

Douglas J. Steele

Personally, I'd use a Delete query to delete it, rather than relying on menu
options.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



jervin via AccessMonster.com said:
There is no error appear, It will just prompt me " Do you want to delete
this
req?" yes and no option, But when i click yes my record is still there it
wont delete...thanks for quick reply

So what does happen? Do you get an error message? If so, what is it? Do
you
get any of the message boxes appearing? If so, which one(s)?

The End If definitely should not be after line a.

Putting error trapping into your routine would probably be a good idea to
help debug problems. As well, your code could be better written as:

Private Sub checkpaassword_Click()

On Error GoTo Err_checkpaassword_Click

If IsNull(Forms!frmpassIss!Text0.Value) Then
MsgBox "It is not a blank Password...Try again."
Me!Text0.SetFocus
ElseIf (Forms!frmpassIss!Text0 <> "vincent") Then
MsgBox "Wrong Password...Try again."
Me!Text0.SetFocus
Else
If MsgBox("Do you want to DELETE this req ?", vbQuestion + vbYesNo,
"Delete Req?") = vbYes Then
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
DoCmd.Close acForm, "frmpassIss"
End If
End If

End_checkpaassword_Click:
Exit Sub

Err_checkpaassword_Click:
MsgBox Err.Number & ": " & Err.Description
Resume End_checkpaassword_Click

End Sub
Hi,
Whats wrong with my second Code? does not delete the record....
[quoted text clipped - 39 lines]
End Sub
**********************
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top