We help IT Professionals succeed at work.

Running different code when yes/no is answered

Cyprexx IT
Cyprexx IT asked
on
how would I run multiable code blocks when yes/no is answered..


example, when yes is answered.. I have 2 functions and a private sub that needs to run.
Comment
Watch Question

Database Architect / Application Developer
CERTIFIED EXPERT
Top Expert 2007
Commented:



' yes ..
  Call YourFunctionName1()
  Call YourFunctionName2()
  SubName

mx
write another function which will internally call all the other functions.
Call this main function when yes/no is clicked.

Author

Commented:
Ohman, thanks!

So.

Call FindNearestTuesday
Sub's here
Call FindNearestThursday
Sub's here


------

That right?
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Application Developer
CERTIFIED EXPERT
Top Expert 2007

Commented:
"private sub that needs to run."
You might want to change the word Private to Public

mx
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2013

Commented:
<You might want to change the word Private to Public >

Unless you are calling it from the same form/module...

Using 'Public' makes it visible across the whole application
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Application Developer
CERTIFIED EXPERT
Top Expert 2007

Commented:
"That right?"

Pretty much ...

Where are the Sub ...relative to where you are calling them from ?

mx

Author

Commented:
Yeah, right after each function. (Also changed all privates to public didn't know that :o)
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Application Developer
CERTIFIED EXPERT
Top Expert 2007

Commented:
"Using 'Public' makes it visible across the whole application"
So ...?
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Application Developer
CERTIFIED EXPERT
Top Expert 2007

Commented:
"Also changed all privates to public didn't know that :o)"
Well, that's not what I said. If ... the sub is in the same module (Form or otherwise), then that is not necessary.  Otherwise, in will need to be Public in order to be 'seen'.

mx
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2013

Commented:
mx -

<So ...? >

My own approach to "Public" is the same as my approach to "Global" variables (minimize the use).  If a function is specific to a given form, why make it public?  In this case, from previous questions, all of the functions/subs reside in the same module, so it is just not necessary.
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Application Developer
CERTIFIED EXPERT
Top Expert 2007

Commented:
All I'm saying is ... it's really not going to hurt anything if you do. Not saying that I would.  However, it might .. be more problematic in a multi developer environment .

Author

Commented:
I'm having some issues, actually. Umm.. Maybe I'm doing something wrong...


This correct?
Public Sub DayWorkComplete_BeforeUpdate(Cancel As Integer)

 If MsgBox("Is displayed date piror to current date?", 52, "Answer the question, bro") = vbYes Then
     ' Do yes
    Call AddWorkDays
    Sub DayWorkComplete()
    Call GetNearestTuesday
       
 Else
    ' Do No
 End If

End Sub

Open in new window

DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Application Developer
CERTIFIED EXPERT
Top Expert 2007

Commented:
And for that matter, I have zero use for Subs - other than the built in Sub for events.

mx

Author

Commented:
Keep In mind, all my functions and subs are still there. I'm just calling the names
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2013

Commented:
You need to pass the parameters...
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2013

Commented:
Just as an example:

GetNearestTuesday Me.YourDateField  'This is an alternate syntax
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2013

Commented:
>> Not saying that I would.

*Exactly*  It's not good practice - and worth investigating before suggesting it.
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Application Developer
CERTIFIED EXPERT
Top Expert 2007

Commented:
Like this -

    Call AddWorkDays
    DayWorkComplete                        
    Call GetNearestTuesday
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Application Developer
CERTIFIED EXPERT
Top Expert 2007

Commented:
OR

    Call AddWorkDays (ParametersIfAny)
    Call DayWorkComplete (ParametersIfAny)                      
    Call GetNearestTuesday (ParametersIfAny)

I prefer the word Call because it clearly indicates what you are doing ...
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Application Developer
CERTIFIED EXPERT
Top Expert 2007

Commented:
I'm a bit confused by this ... in bold


Public Sub DayWorkComplete_BeforeUpdate(Cancel As Integer)

 If MsgBox("Is displayed date piror to current date?", 52, "Answer the question, bro") = vbYes Then
     ' Do yes
    Call AddWorkDays
    Call DayWorkComplete()  ' You are calling the sub you are in ?  If so, no can do ...
    Call GetNearestTuesday
       
 Else
    ' Do No
 End If

End Sub

Explore More ContentExplore courses, solutions, and other research materials related to this topic.