Link to home
Start Free TrialLog in
Avatar of TSTechNA
TSTechNA

asked on

Access VBA

i can't figure out why the below code doesn't work
it's pretty self explanatory i guess
----------------------------------------------------------------------------------------------------------------------------
DeleteConfirmation = MsgBox("Are you sure you weant to delete this Project?", vbYesNo, "Delete?")

If vbYes Then
DoCmd.RunCommand acCmdDeleteRecord
DoCmd.GoToRecord , , acPrevious
MsgBox "The Project has been deleted.", vbInformation, "Project deleted"
Exit Sub
ElseIf vbNo Then
MsgBox "The deletion has been cancelled.", vbInformation, "Deletion cancelled"
End Sub

any help would be appreciated
Avatar of peter57r
peter57r
Flag of United Kingdom of Great Britain and Northern Ireland image

If DeleteConfirmation = vbYes Then...
same for No

You should change "ElseIf vbNo Then" to "Else". If you cancel the the msgbox you will no get vbNo.

But what's the problem ? Is it only this.
And on the first line "If vbYes Then" should also be "If DeleteConfirmation = vbYes Then"
Avatar of TSTechNA
TSTechNA

ASKER

i tried that as well
it doesn't work either

when i click the button containing the code nothing happens
Have you add it a breack point to check if the code runs there ?
ASKER CERTIFIED SOLUTION
Avatar of Jim Horn
Jim Horn
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Please post the entire procedure for the button.
OM Gang
the below code doesn't work either
------------------------------------------------------------------------------------------------------------------------
DeleteConfirmation = MsgBox("Are you sure you weant to delete this Project?", vbYesNo, "Delete?")
If DeleteConfirmation = vbYes Then
DoCmd.RunCommand acCmdDeleteRecord
DoCmd.GoToRecord , , acPrevious
MsgBox "The Project has been deleted.", vbInformation, "Project deleted"
Else
If DeleteConfirmation = vbNo Then
MsgBox "The deletion has been cancelled.", vbInformation, "Deletion cancelled"
End If
End Sub
and i tried the following as well and it doesn't work even though i figured this one wouldn't anyway
------------------------------------------------------------------------------------------------------------------------

deleteconfirmation = MsgBox("Are you sure you weant to delete this Project?", vbYesNo, "Delete?")
If vbYes = True Then
DoCmd.RunCommand acCmdDeleteRecord
DoCmd.GoToRecord , , acPrevious
MsgBox "The Project has been deleted.", vbInformation, "Project deleted"
Else
If vbNo = True Then
MsgBox "The deletion has been cancelled.", vbInformation, "Deletion cancelled"
End If
End Sub
change this

deleteconfirmation = MsgBox("Are you sure you weant to delete this Project?", vbYesNo, "Delete?")

to


deleteconfirmation = (MsgBox("Are you sure you weant to delete this Project?", vbYesNo, "Delete?") )
And:

If MsgBox("Are you sure you weant to delete this Project?", vbYesNo, "Delete?") = vbYes Then
 ..
Else
 ...
End If

deleteconfirmation = (MsgBox("Are you sure you weant to delete this Project?", vbYesNo, "Delete?") )
If deleteconfirmation = vbYes Then
DoCmd.RunCommand acCmdDeleteRecord
DoCmd.GoToRecord , , acPrevious
MsgBox "The Project has been deleted.", vbInformation, "Project deleted"
Else

MsgBox "The deletion has been cancelled.", vbInformation, "Deletion cancelled"
End If
End Sub
Please define
'Doesn't work'
>the below code doesn't work either
.. and explain for us what troubleshooting methods you are using beyond observing that it 'doesn't work'.

I'm still fairly comfortable that my Select Case block will work for you, given the details you have provided us.
ok

the select case works, i have no idea why it doesn't work the other way, that code worked in vb6 is all i know but in access 2007 it doesn't do a thing but it doesn't produce errors either.

i have noticed in access 2007 (not sure about 2003) that you can type erroneous code and it won't complain a bit but the code is not functional....strange

anyway, thanks for all the help
the below code doesn't work in access 2007 either.....not sure why
it produces no error(s) but doesn't do a thing when the button is clicked.
--------------------------------------------------------------------------------------------------------

DeleteConfirmation = (MsgBox("Are you sure you weant to delete this Project?", vbYesNo, "Delete?"))
If DeleteConfirmation = vbYes Then
DoCmd.RunCommand acCmdDeleteRecord
DoCmd.GoToRecord , , acPrevious
MsgBox "The Project has been deleted.", vbInformation, "Project deleted"
Else
MsgBox "The deletion has been cancelled.", vbInformation, "Deletion cancelled"
End If
End Sub
 
did you check if there is an [Event Procedure] in the click event of the button on the Property sheet-  Event tab of the command button