Solved

changing the executable code behind a button on the fly

Posted on 2012-03-12
3
388 Views
Last Modified: 2012-03-12
what is the proper syntax to set the value of a button/control to difference functions depending on which phase of the the process the user is in?

I am in the process of converting and cleaning up old Macro code into vba.  It does not like the setting of a control/button.

I have a form where the "ok" button could launch 1 of 3 functions to be used.  Like if field 3  = FTIRDN then it should execute the function named:  FM_ViDataX_ApSelect_FTIR_OK

Private Sub cmd_ImportFTIR_Click()

Dim i As Integer
   
   On Error GoTo cmd_ImportFTIR_Click_Error
    
    gApNO = Me.ApNo
    ' FM_ViDataX_ApSelect - Form - - - Edit - Normal ==> Self Explanatory
    DoCmd.OpenForm "FM_ViDataX_ApSelect", acNormal, "", "", acEdit, acNormal
    '-- Set the initial form values.
    Forms![FM_ViDataX_ApSelect]![txtApNo].Value = UCase$(Trim$(gApNO))
    Forms![FM_ViDataX_ApSelect]![txtFileName].Value = gApNO & "\Access\FTIR.txt"
    ' ViDataX_Set_FTIR_Values - Code ==> Set the default FTIR download values for FM_ViDataX_ApSelect form.
    Forms![FM_ViDataX_ApSelect]![txtXactnName].Value = "FTIRDN"
    ' Sets the click event on the OK button to run FM_ViDataX_ApSelect._FTIR_OK
    i = 1
 '   Forms!FM_ViDataX_ApSelect!cmdOK.OnClick = "FM_ViDataX_ApSelect_FTIR_OK"

   On Error GoTo 0
   Exit Sub

cmd_ImportFTIR_Click_Error:

    MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure cmd_ImportFTIR_Click of VBA Document Form_FS_MSB"

End Sub

Open in new window


As you can see I have tried it within the quotes and it gives me an error msg.  Can't find the object FM_ViDataX_ApSelect_FTIR_OK

and if I try it w/o the quotes then it just executes the code automatically.

Please keep in mind that this OK button should be used in 3 different instances using different function names.  What is the proper syntax?

Karen
0
Comment
Question by:Karen Schaefer
  • 2
3 Comments
 
LVL 15

Accepted Solution

by:
Simon Ball earned 500 total points
ID: 37711968
in the button click event use

select case <variable>

case <variable> = 1
'do some work
case <variable> = 2
'do some work
Case else
'do some work
end select

to handle which stage the page is in when button clicked.

you just use a public variable to hold a record of page stage
0
 

Author Closing Comment

by:Karen Schaefer
ID: 37712098
we were on the same page.  thanks for your input.
0
 
LVL 15

Expert Comment

by:Simon Ball
ID: 37712105
thanks! :P
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question