Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Beetlejuice
 
Posts: n/a
Default Novice - MsgBox Yes/No - Continue if Yes, Close if No

I have a form to be completed by staff ONLY if they have approval to proceed
with the work. I've managed (with this group's assistance!) to have a
message box pop up but I want to add a wrinkle where if they press "yes",
they can proceed to fill in the form, if they press "no", the file closes.
I've never done If/Then in VBA (this is actually my first foray into VBA).
Help please!:

Sub Auto_open()
MsgBox "The Project Manager's or Project Administrator's approval must be
obtained prior to proceeding with this work. Has approval been obtained?.",
vbYesNo, "WARNING"
End Sub
  #2   Report Post  
Dave Peterson
 
Posts: n/a
Default

Option Explicit
Sub Auto_open()
Dim resp As Long
resp = MsgBox(prompt:="The Project Manager's or Project Administrator's" & _
" approval must be obtained prior to proceeding with" & _
" this work." & vbLf & vbLf & "Has approval been obtained?", _
Buttons:=vbYesNo, Title:="Warning")

If resp = vbNo Then
ThisWorkbook.Close savechanges:=False
End If

End Sub

I inserted a couple of vblf's to make it easier to read (for me, anyway).


Beetlejuice wrote:

I have a form to be completed by staff ONLY if they have approval to proceed
with the work. I've managed (with this group's assistance!) to have a
message box pop up but I want to add a wrinkle where if they press "yes",
they can proceed to fill in the form, if they press "no", the file closes.
I've never done If/Then in VBA (this is actually my first foray into VBA).
Help please!:

Sub Auto_open()
MsgBox "The Project Manager's or Project Administrator's approval must be
obtained prior to proceeding with this work. Has approval been obtained?.",
vbYesNo, "WARNING"
End Sub


--

Dave Peterson
  #3   Report Post  
Beetlejuice
 
Posts: n/a
Default

Thank you! It works like a charm - I'm sure I'll be cursed from here to
eternity.

"FSt1" wrote:

hi,
if msgbox("The Project Manager's or Project Administrator's " & vbnewline _
& "approval must be obtained prior to proceeding with this work. " &
vbnewline _
& "Has approval been obtained?.", vbYesNo, "WARNING") = vbno then
Activeworkbook.close savechanges:=false
end if



"Beetlejuice" wrote:

I have a form to be completed by staff ONLY if they have approval to proceed
with the work. I've managed (with this group's assistance!) to have a
message box pop up but I want to add a wrinkle where if they press "yes",
they can proceed to fill in the form, if they press "no", the file closes.
I've never done If/Then in VBA (this is actually my first foray into VBA).
Help please!:

Sub Auto_open()
MsgBox "The Project Manager's or Project Administrator's approval must be
obtained prior to proceeding with this work. Has approval been obtained?.",
vbYesNo, "WARNING"
End Sub

  #4   Report Post  
David Hepner
 
Posts: n/a
Default

With out looking at your code I don't know what is causing the problem. I
didn't include the Sub Auto_open() in my previous response. See if this works
for you:


Sub Auto_open()

Dim response As Integer
Dim msg As String

msg = "The Project Manager's or Project Administrator's approval must be
obtained prior to proceeding with this work. Has approval been obtained?."
response = MsgBox(msg, vbYesNo, "WARNING")
If response = vbYes Then ' User chose Yes.
MyString = "Yes" ' Perform some action.
Else ' User chose No.
MyString = "No" ' Perform some action."
End If

End Sub






"Beetlejuice" wrote:

I keep getting an "Invalid outside procedure"

"David Hepner" wrote:

Try this:

Dim response As Integer
response = MsgBox("The Project Manager's or Project Administrator's approval
must be obtained prior to proceeding with this work. Has approval been
obtained?.", vbYesNo, "WARNING")
If response = vbYes Then ' User chose Yes.
MyString = "Yes" ' Perform some action.
Else ' User chose No.
MyString = "No" ' Perform some action."
End If



"Beetlejuice" wrote:

I have a form to be completed by staff ONLY if they have approval to proceed
with the work. I've managed (with this group's assistance!) to have a
message box pop up but I want to add a wrinkle where if they press "yes",
they can proceed to fill in the form, if they press "no", the file closes.
I've never done If/Then in VBA (this is actually my first foray into VBA).
Help please!:

Sub Auto_open()
MsgBox "The Project Manager's or Project Administrator's approval must be
obtained prior to proceeding with this work. Has approval been obtained?.",
vbYesNo, "WARNING"
End Sub

  #5   Report Post  
David Hepner
 
Posts: n/a
Default

Try this:

Dim response As Integer
response = MsgBox("The Project Manager's or Project Administrator's approval
must be obtained prior to proceeding with this work. Has approval been
obtained?.", vbYesNo, "WARNING")
If response = vbYes Then ' User chose Yes.
MyString = "Yes" ' Perform some action.
Else ' User chose No.
MyString = "No" ' Perform some action."
End If



"Beetlejuice" wrote:

I have a form to be completed by staff ONLY if they have approval to proceed
with the work. I've managed (with this group's assistance!) to have a
message box pop up but I want to add a wrinkle where if they press "yes",
they can proceed to fill in the form, if they press "no", the file closes.
I've never done If/Then in VBA (this is actually my first foray into VBA).
Help please!:

Sub Auto_open()
MsgBox "The Project Manager's or Project Administrator's approval must be
obtained prior to proceeding with this work. Has approval been obtained?.",
vbYesNo, "WARNING"
End Sub



  #6   Report Post  
FSt1
 
Posts: n/a
Default

hi,
if msgbox("The Project Manager's or Project Administrator's " & vbnewline _
& "approval must be obtained prior to proceeding with this work. " &
vbnewline _
& "Has approval been obtained?.", vbYesNo, "WARNING") = vbno then
Activeworkbook.close savechanges:=false
end if



"Beetlejuice" wrote:

I have a form to be completed by staff ONLY if they have approval to proceed
with the work. I've managed (with this group's assistance!) to have a
message box pop up but I want to add a wrinkle where if they press "yes",
they can proceed to fill in the form, if they press "no", the file closes.
I've never done If/Then in VBA (this is actually my first foray into VBA).
Help please!:

Sub Auto_open()
MsgBox "The Project Manager's or Project Administrator's approval must be
obtained prior to proceeding with this work. Has approval been obtained?.",
vbYesNo, "WARNING"
End Sub

  #7   Report Post  
Beetlejuice
 
Posts: n/a
Default

I keep getting an "Invalid outside procedure"

"David Hepner" wrote:

Try this:

Dim response As Integer
response = MsgBox("The Project Manager's or Project Administrator's approval
must be obtained prior to proceeding with this work. Has approval been
obtained?.", vbYesNo, "WARNING")
If response = vbYes Then ' User chose Yes.
MyString = "Yes" ' Perform some action.
Else ' User chose No.
MyString = "No" ' Perform some action."
End If



"Beetlejuice" wrote:

I have a form to be completed by staff ONLY if they have approval to proceed
with the work. I've managed (with this group's assistance!) to have a
message box pop up but I want to add a wrinkle where if they press "yes",
they can proceed to fill in the form, if they press "no", the file closes.
I've never done If/Then in VBA (this is actually my first foray into VBA).
Help please!:

Sub Auto_open()
MsgBox "The Project Manager's or Project Administrator's approval must be
obtained prior to proceeding with this work. Has approval been obtained?.",
vbYesNo, "WARNING"
End Sub

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 10:32 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"