Change to vbYesNocancel

  • Thread starter Thread starter Nick
  • Start date Start date
N

Nick

If Year(Me.[oTDLdaTE]) <> Year(Date) Then
MsgBox "Year is incorrect, must be current year", , "Cannot continue "
Cancel = True
End If
I would like to chang to vbYesNoCancel. Some thing like this
If Year(Me.[oTDLdaTE]) <> Year(Date) then
"MsgBox" vbYesNoCancel"Do you wish to retain date entered" IF "Yes" Msgbox
Date retained IF "No" Msgbox "Please enter date"
I am not sure how to use vbYesNoCancel.
 
Nick,

I assume this code is in the BeforeUpdate event of a control on your form,
or in the forms BeforeUpdate event. An example might be:

Private Sub Form_BeforeUpdate(Cancel as integer)

Dim intResponse as integer
Dim strMsg as string

if Year(me.[oTDLdate]) <> Year(Date()) then
strMsg = "Do you wish to retain the date entered?"
intResponse = msgbox(strMsg, vbYesNoCancel)
if intResponse = vbYes then
msgbox "Date retained"
elseif intResponse = vbNo then
msgbox "Please enter date!"
Cancel = true
else if intResponse = vbCancel then
'insert some code to do something here
'you didn't indicate what you want to do if
'the user selects 'Cancel'
end if
end if

End Sub

HTH
Dale
 
Easy way would be to use a Select Case statement:

Dim lngAnswer As Long

lngAnswer = MsgBox("Do you wish to retain date entered", vbQuestion +
vbYesNoCancel)
Select Case lngAnswer
Case vbYes
'Put the Yes code Here
Case vbNo
'Put the No code Here
Case vbCancel
'Put the Cancel Code Here
End Select
 
Thank you, I did know what I wanted code to do. How would I clear field and
cancel entry?
Dale Fye said:
Nick,

I assume this code is in the BeforeUpdate event of a control on your form,
or in the forms BeforeUpdate event. An example might be:

Private Sub Form_BeforeUpdate(Cancel as integer)

Dim intResponse as integer
Dim strMsg as string

if Year(me.[oTDLdate]) <> Year(Date()) then
strMsg = "Do you wish to retain the date entered?"
intResponse = msgbox(strMsg, vbYesNoCancel)
if intResponse = vbYes then
msgbox "Date retained"
elseif intResponse = vbNo then
msgbox "Please enter date!"
Cancel = true
else if intResponse = vbCancel then
'insert some code to do something here
'you didn't indicate what you want to do if
'the user selects 'Cancel'
end if
end if

End Sub

HTH
Dale
--
Don''t forget to rate the post if it was helpful!

email address is invalid
Please reply to newsgroup only.



Nick said:
If Year(Me.[oTDLdaTE]) <> Year(Date) Then
MsgBox "Year is incorrect, must be current year", , "Cannot continue "
Cancel = True
End If
I would like to chang to vbYesNoCancel. Some thing like this
If Year(Me.[oTDLdaTE]) <> Year(Date) then
"MsgBox" vbYesNoCancel"Do you wish to retain date entered" IF "Yes" Msgbox
Date retained IF "No" Msgbox "Please enter date"
I am not sure how to use vbYesNoCancel.
 
Back
Top