Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

changing the executable code behind a button on the fly

Posted on 2012-03-12
3
Medium Priority
?
394 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

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

Question has a verified solution.

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

This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

596 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