?
Solved

changing the executable code behind a button on the fly

Posted on 2012-03-12
3
Medium Priority
?
392 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 15

Accepted Solution

by:
Simon Ball earned 2000 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

Python: Series & Data Frames With Pandas

Learn the basics of Python’s pandas library of series & data frames and how we can use these tools for data manipulation.

Question has a verified solution.

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

This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
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.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
Suggested Courses

770 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