Running code after a Yes/No response

coley

Coley
Local time
Today, 22:59
Joined
Feb 22, 2005
Messages
39
Hi

I have this code

Dim UserResponse As Integer
UserResponse = MsgBox("Do you want to add a New Project?", vbYesNo, "Add a new Project")
If UserResponse = vbYes Then

What I want is when Yes is clicked is to run another bit of code I have typed for another procedure.



Thanks

Keith
 
Code:
If MsgBox("Do you want to add a New Project?", vbYesNo, "Add a new Project") = vbYes then

   Do stuff

End if

???
:) Ken
 
great!!

any normal answers from any normal people
 
coley said:
Dim UserResponse As Integer

Since the response you will be receiving from the message box (the numerical value of either vbYes or vbNo) will never exceed 255 there is no need to declare UserResponse as an Integer. Declaring it as a Byte would be more appropriate.

You probably won't need the UserResponse variable anyway, as Ken suggests, as you are only asking a quick question and acting upon it rather than referring to the response multiple times.

Code:
If MsgBox("Your Question", vbQuestion + vbYesNo, "Title") = vbYes Then
    YourSub ' Just put the name of your sub here
End If

Also, what was wrong with Ken's answer?
 
Since you gave only limited information to start with you can only expect to get a limited reply
 
coley said:
great!!

any normal answers from any normal people
How do you define normal? :p

Code:
If MsgBox("Do you want to add a New Project?", vbQuestion + vbYesNo, "Add a new Project") = vbYes Then
    
   Call YourFunctionNameHere
   
Else
    
    MsgBox "User clicked No"
    
End If
 
ghudson said:
How do you define normal? :p

Code:
If MsgBox("Do you want to add a New Project?", vbQuestion + vbYesNo, "Add a new Project") = vbYes Then
    
   Call YourFunctionNameHere
   
Else
    
    MsgBox "User clicked No"
    
End If


Sorry, that's not normal either. Who would ever name a function 'YourFunctionNameHere'

:eek:
 
thanks to all the people who answered this, apart from Ken because 'Do Stuff' isnt really that helpful, is it?

cheers!!!
 
Sorry. I'll try harder next time.

:o Ken
 
DoStuff may not be helpful.

But run another bit of code I have typed for another procedure isn't really that informative. ;)
 
Fair point, sorry to you all, i will try and explain more carefully in future

coley
 
Please Help

Hi

This is my code:

Private Sub Add_new_request_Click()
If MsgBox("Do you want to add a New Project?", vbQuestion + vbYesNo, "Add a new Project?") = vbYes Then
DoCmd.OpenForm ("Project Log Sheet")
DoCmd.Maximize
DoCmd.Close acForm, ("Main Page")

Here I need code to run another procedure called ‘Private Sub AddNewProject_Click()'

Else
DoCmd.Close acForm, ("Project Log Sheet")
DoCmd.OpenForm ("Main Page")
DoCmd.Maximize
End If
End Sub

What code do i need to put to run the procedure, i have tried both Call and YourSub but it aint working

Please help
 
This didn't work?

Code:
Call AddNewProject_Click

Is the procedure on the same module?

Also, I merged this thread as it is an extension (if not actually the same) of your previous question.
 
does not work

i get this error

Compile error:
Sub or Function not defined

I have no code in any modules, on the Project Explorer all my Forms are listed with codes asscoited to them.

Is it best to use modules then?
 
coley said:
I have no code in any modules, on the Project Explorer all my Forms are listed with codes asscoited to them.

If you have no code in any modules then I'm surprised that you have code in your database since the only place you can put code in a module - forms (and reports) just have modules associated with them.

I'm guessing either:


  1. the procedure you are trying to call is not on the same module as that which you are calling it from.

    i.e. one on "Project Log Sheet" as you call it from the module attached to the form "Main Page"; or
  2. The procedures are both on "Main Page" but you have closed the form before you can call the procedure attached to it.
 
ok i see,

I do have code in my database but no modules, so they are linked to the forms. I dont have a clue regarding Modules, but is it possible to put all my code into one module so they are all in the one place, will this help?

cheers
 
Not exactly. With code used througout the program you can put it into one big module but it would load everything into the memory even when you don't require it. Code attached to events requires to be within the module of the object it is as attached to (i.e. form or report).

What would be more of value is to think about the process your code is taking and restructure that appropriately.
 
If your database is small, which it probably is, just make the sub Public instead of Private.

Also, you don't need to use "Call"
 
Modest,

something like this?

Public Sub Add_new_request_Click()

DoCmd.OpenForm ("Project Log Sheet")

DoCmd.Maximize

DoCmd.Close acForm, ("Main Page")

If MsgBox("Do you want to add a New Project?", vbQuestion + vbYesNo, "Add a new Project?") = vbYes Then

DoCmd.OpenForm ("Project Log Sheet")

DoCmd.Maximize
DoCmd.Close acForm, ("Main Page")

Call AddNewProject_Click

End If

End Sub
 

Users who are viewing this thread

Back
Top Bottom