Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

no opotion in a msgbox 1

Status
Not open for further replies.

clobo

Technical User
Sep 16, 2008
5
PT
Hello

I have a data base to control the loan dates of plants. On a table, I have a field with the Send date of the plants and the Predicted date of return of the plants. I have some code so that when I introduce a date in the Send date field, on the Predicted date it appears the Send date plus 6 months. This works fine if there is no date in the predicted date field.

But if there is a value in the predicted date (is not null), and I change the send date, I have a code that warns me that the predicted date is going to change. This appears with a msgbox with a yes/no option. If I click yes, the predicted date adds 6 months. The problem is that when I click no, the computer adds 6 months to the predicted date when what I want is for the dates to stay the same. It would be like as if I had cancelled the changes.

Here is the code I have for this. Can somebody help me with the code for the no option, so that if I select no, nothing changes.


Private Sub Send_date_AfterUpdate()
If IsNull(Me.Predicted_date) Then
GoTo ver
Else
GoTo wer
End If

wer:
If MsgBox("You are about to change the Predicted date." _
& vbCrLf & vbCrLf & "Do you wish to continue?" _
, vbYesNo, "Change predicted date") = vbYes Then
Me.Predicted_date = DateAdd("m", 6, Me.Send_date.Text)
End If

ver:
Me.Predicted_date = DateAdd("m", 6, Me.Predicted_date.Text)
End Sub


Thanks in advance for your help. Sorry for asking these questions that may seem quite basic but I’m learning by my self.
 
Mate,

No matter what the user does in "wer", "ver" will always run after it.

AVOID goto command at all costs except error handling where you want to have a tough hand on the shoulder.

Use this:

Code:
Private Sub Send_date_AfterUpdate()
    If isdate(Me.Predicted_date) Then 
        If MsgBox("You are about to change the Predicted date." _
         & vbCrLf & vbCrLf & "Do you wish to continue?" _
         , vbYesNo, "Change predicted date") = vbYes Then
            Me.Predicted_date = DateAdd("m", 6,   Me.Send_date.Text)
         End If
    Else
         Me.Predicted_date = DateAdd("m", 6, Me.Predicted_date.Text)
    End If
End Sub

if you wan original code to work then chuck in an Exit Sub but not recommended :)

JB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top