Link to home
Create AccountLog in
Avatar of Cyprexx IT
Cyprexx IT

asked on

Running different code when yes/no is answered

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.
ASKER CERTIFIED SOLUTION
Avatar of DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
write another function which will internally call all the other functions.
Call this main function when yes/no is clicked.
Avatar of Cyprexx IT
Cyprexx IT

ASKER

Ohman, thanks!

So.

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


------

That right?
"private sub that needs to run."
You might want to change the word Private to Public

mx
<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
"That right?"

Pretty much ...

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

mx
Yeah, right after each function. (Also changed all privates to public didn't know that :o)
"Using 'Public' makes it visible across the whole application"
So ...?
"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
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.
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 .
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

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

mx
Keep In mind, all my functions and subs are still there. I'm just calling the names
You need to pass the parameters...
Just as an example:

GetNearestTuesday Me.YourDateField  'This is an alternate syntax
>> Not saying that I would.

*Exactly*  It's not good practice - and worth investigating before suggesting it.
Like this -

    Call AddWorkDays
    DayWorkComplete                        
    Call GetNearestTuesday
OR

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

I prefer the word Call because it clearly indicates what you are doing ...
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