Case vbNo

S

shiro

I have code that doesn't work in case vbNo and don't know why.
Please help.The code works on form BeforeUpdate even but not on
my command button click even.Any guidance would be greatly appreciated
Thank's

Private Sub AddSpec_cmd_Click()
On Error GoTo Err_AddSpec_cmd_Click

Dim strMessage As String
Dim intResponse As Integer
intResponse = MsgBox("Is the spec correct?", vbYesNoCancel, "Confirm")
Select Case intResponse
Case vbYes
If IsNull(Me.Model) Then
strMessage = strMessage & _
" Enter Model Name" & vbCrLf
End If

If InputVoltage.Value < 11 Then
strMessage = strMessage & _
" Input correct voltage rate " & vbCrLf
End If

If Len(strMessage) = 0 Then
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, ,
acMenuVer70

Else
MsgBox strMessage, vbOKOnly, "Error"
End If

Case vbNo
If MsgBox("Delete data?", vbOKCancel, "Confirm") = vbOK Then
Me.Undo
End If

Case vbCancel
Cancel = True

End Select

Exit_AddSpec_cmd_Click:
Exit Sub

Err_AddSpec_cmd_Click:
MsgBox Err.Description
Resume Exit_AddSpec_cmd_Click:

End Sub
 
J

Jeanette Cunningham

Hi Shiro,
the Before Update is the place for that code you posted.
In your button on click procedure you put code to make the BeforeUpdate code
fire.

Something like this:
Private Sub MyButton_Click()
If Me.Dirty = True Then
Me.Dirty = False
End If

the bit that sets the form's dirty property to false is the bit that makes
Access fire off the BeforeUpdate code.

Jeanette Cunningham
 
S

shiro

Addition
It return me error message :
Variable not define
to the statement Cancel = True
 
B

boblarson

Read Jeanette's response for the definitive answer for you. The problem with
the Cancel = True in your Click event is that Cancel is not an option within
a command button's click event, whereas it is available as an option in a
Before Update event.

So, because it isn't included in the Click event, it isn't declared and
that's why you are getting that error.

So, read Jeanette's post and follow her instructions and you should be good
to go.
--
Bob Larson
Access World Forums Super Moderator
Utter Access VIP
Tutorials at http://www.btabdevelopment.com
If my post was helpful to you, please rate the post.
__________________________________
 
J

Jeanette Cunningham

Shiro,
there is a line that needs removing

Case vbCancel
Cancel = True

comment out the line Cancel = True

the line Cancel = True is what you would use to cancel the before update
event for the form.

What do you want to happen when a user clicks the cancel button on your
message box?
This is what you have to put in the code under
Case vbCancel

Maybe you just want the message box to close without doing anything when a
user clicks cancel on the message box.
If so, you do it like this

Select case etc, etc
Case vbYes
'your code here

Case vbNo
'your code

Case Cancel

End Select

Jeanette Cunningham
 
S

shiro

Thank's fro quick reply,
but I found new problem in my BeforeUpdate even ( maybe )
It is occured if I close the form.

If I had filled my PK field then close the form,
the data still can be saved,although there are still another
fields leave blank and need to be fill ( mentioned in my code ).

How to prevent this.Thank's for provide time for helping me.
 

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