We help IT Professionals succeed at work.

Access VBA

TSTechNA
TSTechNA asked
on
310 Views
Last Modified: 2013-11-27
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
Comment
Watch Question

CERTIFIED EXPERT

Commented:
If DeleteConfirmation = vbYes Then...
same for No
Jorge PaulinoIT Pro/Developer
CERTIFIED EXPERT
Top Expert 2008

Commented:

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.
Jorge PaulinoIT Pro/Developer
CERTIFIED EXPERT
Top Expert 2008

Commented:
And on the first line "If vbYes Then" should also be "If DeleteConfirmation = vbYes Then"

Author

Commented:
i tried that as well
it doesn't work either

when i click the button containing the code nothing happens
Jorge PaulinoIT Pro/Developer
CERTIFIED EXPERT
Top Expert 2008

Commented:
Have you add it a breack point to check if the code runs there ?
SQL Server Data Dude
CERTIFIED EXPERT
Most Valuable Expert 2013
Author of the Year 2015
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
omgangIT Manager
CERTIFIED EXPERT

Commented:
Please post the entire procedure for the button.
OM Gang

Author

Commented:
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

Author

Commented:
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
CERTIFIED EXPERT
Top Expert 2016

Commented:
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?") )
Jorge PaulinoIT Pro/Developer
CERTIFIED EXPERT
Top Expert 2008

Commented:
And:

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

Commented:

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
CERTIFIED EXPERT

Commented:
Please define
'Doesn't work'
Jim HornSQL Server Data Dude
CERTIFIED EXPERT
Most Valuable Expert 2013
Author of the Year 2015

Commented:
>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.

Author

Commented:
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

Author

Commented:
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
CERTIFIED EXPERT
Top Expert 2016

Commented:
 
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
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.