Throw different message box when same function is called 2nd time (1 Viewer)

EEH_Help

Member
Local time
Today, 09:28
Joined
Feb 15, 2020
Messages
32
Hello:

I use an AutoExec routine which does the following:

1. Imports 10 tables where table names have prefix "Step_4_*"
2. Renames those 10 tables and removes prefix "Step_4_*" so that table names now start with "tbl_*"
3. Re-Imports same 10 tables (again) but now leaves prefix intact.

As a result I have 10 tables with prefix "tbl_*" AND 10 tables with prefix "Step_4_*". The latter works great and DOES NOT need modification.

Upon execution of the 1st import function call, the following message box is thrown:

Code:
MsgBox "Message #1"
    n = n + 1

Now, when I get to step #3 and I re-import the tables a 2nd time, I end up w/ the "Message #1" again. Instead, however, I'd like to throw the second message box instead.

Code:
MsgBox "Message #2"


I tried including a simple counter (e.g., n = 1)

Code:
If n = 1 Then

        ... throw 1st message
    Else

        ... throw 2nd message
    End

Unfortunately, I only get to see "Message #1" since n will always equal = 1 (in this case).

Does anyone have a suggestion how to throw message #2 (vs. #1) when the same function is called a 2nd time?
 

theDBguy

I’m here to help
Staff member
Local time
Today, 06:28
Joined
Oct 29, 2018
Messages
16,078
Can you use a TempVar or a global variable?
 

theDBguy

I’m here to help
Staff member
Local time
Today, 06:28
Joined
Oct 29, 2018
Messages
16,078
Certainly... how/where would I set it? In a different function/module?
Could be in the same module. Being a TempVar or global variable, it's value does not go away when the function finished running.
 

EEH_Help

Member
Local time
Today, 09:28
Joined
Feb 15, 2020
Messages
32
My line of thinking was exactly that where n = 1 during the 1st loop and n would be = 2 during the 2nd execution. Apparently, that did not work.

How do I declare n or any TempVar so that its value will be stored?
 

theDBguy

I’m here to help
Staff member
Local time
Today, 06:28
Joined
Oct 29, 2018
Messages
16,078
My line of thinking was exactly that where n = 1 during the 1st loop and n would be = 2 during the 2nd execution. Apparently, that did not work.

How do I declare n or any TempVar so that its value will be stored?
Something like:
Code:
If Nz(TempVars!VariableName,0)=1 Then
    'Function already ran
Else
    TempVars!VariableName=1
End If
 

EEH_Help

Member
Local time
Today, 09:28
Joined
Feb 15, 2020
Messages
32
theDBguy -- that's the perfect solution. Works like a charm! Many thanks.
 

CJ_London

Super Moderator
Staff member
Local time
Today, 14:28
Joined
Feb 19, 2013
Messages
13,231
You can also use a static Boolean variable within you function
Code:
Static b as boolean
‘As declared b will be false
If b then
   Msg 2
Else
   Msg 1
End if
B=not b
 

Users who are viewing this thread

Top Bottom