What is this structure?

sjr1917

Registered User.
Local time
Today, 07:13
Joined
Dec 11, 2012
Messages
47
Is the Btns() an anonymous function?? Can you point me to the correct description for it.

It was in a great bit of sample code by forum member r.harrison for his formatted Msgbox:

BtnPressed = Btns(MsgBox(.....)
Select Case BtnPressed
Case Btns(0)
etc
 
I would assume that Btns() is a public function in that database. Doing a ctl-F should let you find it. Or hit Shift-F2 with the cursor in Btns.
 
Should have added this line of code from the top of the Module:

Global Btns(4) As Variant ' Set to the number of buttons on the msgbox form

So is this an array declaration??
Still don't recognize the structure... I'm new enough to Access VBA and it's just enough different that PHP & etc. that I keep being thrown off.
 
It's declaring an array of variant equal to the number of buttons in the Msgbox, plus 1 actually as the numbering starts at 0 not 1.

Code:
Global Btns(4) As Variant ' Set to the number of buttons on the msgbox form
BtnPressed = Btns(MsgBox(.....)
Select Case BtnPressed
Case Btns(0)
etc

The value returned by MsgBox depends on which button was pressed.

Button, value
OK, 1
Cancel, 2
Abort, 3
Retry, 4
Ignore, 5
Yes, 6
No, 7

BtnPressed is set to whatever value is in the array Btns() at the index of that value.

So instead of doing "Select Case" of the values 1 to 7 you are doing "Select Case" based on whatever text (probably) you have set in the array Btns().

You could set up the array as:

Btns(1) = "Your record has been saved" (OK)
Btns(2) = "The changes to your record have been cancelled" (Cancel)
Btns(3) = "You chose to abort the record" (Abort)
etc

Instead of doing

Code:
Select Case MsgBox
Case 1
..
Case 2
..
Case 3
..

you can write your code as

Code:
Select Case btnPressed
  Case Btns(0) ' nothing pressed
    ..
  Case Btns(1) ' Whatever Btns(1) is etc 
    ..
  Case Btns(2)
    ..
  End Select

' You could also use it to display the value as a message without having to
' write a load of If statements.
 
  Me.txtResponse = Btns(btnPressed)

You can change whatever the array Btns() holds and not have to change your code.
 
Last edited:
Thanks Paul & Nigel! The light comes on... seems so obvious in the light of new a day :)
 

Users who are viewing this thread

Back
Top Bottom