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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

vbyesno problem

Status
Not open for further replies.

nevstic

Instructor
Jul 30, 2002
98
GB
Hello all
I wonder if you can help with the following,I have tried the FAQs but cannot make this work completely.


Private Sub Details_Exit(Cancel As Integer)
If IsNull(Me![details]) Then
MsgBox "Would you like to Add some Details?", vbYesNo + vbDefaultButton2, "mine"

If vbYes Then
Cancel = True
Else
If vbNo Then
DoCmd.Go to Next Record or cancel event or something ?
End If

End If
End If
End Sub

My question firstly is can I put this in the "on exit"
and lastly I can only make it work on the first Argument.

Please tell me where I am going wrong here


 
You need to store the value returned by the message box.

Dim IntResponse as Integer

intResponse = MsgBox "Would you like to Add some Details?", vbYesNo + vbDefaultButton2, "mine"

If intResponse = vbYes....

etc

Also you don't need the second If statement
Response MUST be either vbYes or vbNo

so

If intResponse = vbYes then
'do yes stuff
Else
'do no stuff
End If

Hope this helps

 
The msgBox actually returns the value vbYes or vbNo ( if you put the brackets in - else it returns nothing ) so you need:-

Code:
Private Sub Details_Exit(Cancel As Integer)
If IsNull(Me![details]) Then
    If MsgBox("Would you like to Add some Details?", vbYesNo + vbDefaultButton2, "mine") Then

        Cancel = True
    Else   ' ( therefore = vbNo - so )
        DoCmd.Go to Next Record or cancel event or something ?
    End If

End If
End If
End Sub



'ope-that-'elps.

G LS
 
Hiya All
Many thanks for all the response,
But I still have a prob and no Hair !
the following...

Private Sub Details_Exit(Cancel As Integer)

If IsNull(Me![details]) Then

If MsgBox("Would you like to Add some Details?", vbYesNo + vbDefaultButton2, "Reminder") Then
Cancel = True
Else

DoCmd.GoToRecord acNew
End If

End If

End Sub

works as far as the Cancel =True
but also same on the second piece and I cannot get it to go passed the event I.E will always go to the "details" control whether I press Yes or No !

Where oh where Am I going wrong ?

Thanks again in advance of your kind help

Rgds
Desperate Nick

 
Oooooops !

Sorry OM I missed out one important bit in the IF statement

If {what comes back from MsgBox} = vbYes Then

So you need
Code:
If MsgBox("Would you like to Add some Details?", vbYesNo + vbDefaultButton2, "Reminder") = vbYes Then


By the way,
Is Details the name of a field ?
Is Details the name of a control ?

If Detail is a control you don't need the Me! qualifier or the brackets. Use:-
If IsNull(Details) Then




'ope-that-'elps.

G LS
 
Thanks vmucho GLS
also for your patience
This now works exceedingly well

Best regards
Nick
 
Thanks vmucho GLS

Yes, Details is a name of a control

thanks also for your patience
This now works exceedingly well

Best regards
Nick
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top